Arun Selva Kumar
Arun Selva Kumar

Reputation: 2732

How to Add Data Contents to Data Grid in the Same Page without any Database Connectivity?

Say, I have a TextBox - When the User enters contents into TextBox and Click on Add the Content Should Populate in the DataGrid Without any db connectivity. The User Can add repeated items in the TextBox and Click on Add, So Every Value gets Popluated in the Grid. How do I achieve this?

Upvotes: 1

Views: 207

Answers (1)

Nudier Mena
Nudier Mena

Reputation: 3274

You can try something like this, first you have to Imports the System.Collection.Generic namespace

 private List<string> addContent(string content)
{
    //create a generic list of string type
    List<string> s = new List<string>();

    for (int i = 0; i < 10; i++)
    {
        s.Add(content);
    }
    return s;
}

protected void btnAdd_Click(object sender, EventArgs e)
{
   //Passed the List<> as DataSource and then bind the content in the list<> in the  DataGrid
    this.DataGrid1.DataSource = this.addContent(this.txtadd.Text);
    this.DataGrid1.DataBind();

}

I Hope this works for you

Upvotes: 1

Related Questions