Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
how can I create a cutom data table for gridview where row increases automatically and first row displays when user click on add button that is outside from grid?
Posted
Updated 31-Oct-10 20:12pm
v2
Comments
Sunasara Imdadhusen 1-Nov-10 2:12am    
You want to create datatable when clicking on button?

1 solution

Create a datatable first and then bind the table on your gridview
DataTable dtAddGridView = new DataTable("TestTable");
protected void Add_Click(object sender, EventArgs e)
{

C#
if (dtAddGridView.Rows.Count != 0)
        {
            if (dtAddGridView.Columns.Count != 0)
            {
                dtAddGridView.Columns.Add("Name", typeof(string));
                dtAddGridView.Columns.Add("ID", typeof(int));
                dtAddGridView.Columns.Add("Date", typeof(DateTime));
            }


}
DataRow dr = dtAddGridView.NewRow();

dr["Name"] = "test";
dr["ID"] = 100;
dr["Date"] = DateTime.Now;

dtAddGridView.Rows.Add(dr);
GridView1.DataSource = dtAddGridView;
GridView1.DataBind();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900