addin to gridview dynamically
-
hi everybody my problem with gridview I create gridview like this //...................................
//............................................. and in the below I have tow textbox and add button I want when click on add button the value of the tow textbox adding/inserting into the gridview (I want to add more than one value) how can I make that and thanks
-
hi everybody my problem with gridview I create gridview like this //...................................
//............................................. and in the below I have tow textbox and add button I want when click on add button the value of the tow textbox adding/inserting into the gridview (I want to add more than one value) how can I make that and thanks
1:Add textbox items in dataTable 2:Save dataTable in Session 3:Set GridView datasource as dataTable from Session check this sample code
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt;
DataRow drow;
if (Session["datatable"] == null)
{
dt = new DataTable();DataColumn dcol = new DataColumn("Column1", typeof(string)); //adding column to datatable dt.Columns.Add(dcol); int rowcount = 0; drow = dt.NewRow(); dt.Rows.Add(drow); dt.Rows\[rowcount\]\[dcol\] = TextBox1.Text; //add datatable to session Session.Add("datatable", dt); } else { dt = (DataTable)Session\["datatable"\]; drow = dt.NewRow(); dt.Rows.Add(drow); dt.Rows\[dt.Rows.Count-1\]\["Column1"\] = TextBox1.Text; //add datatable to session Session.Add("datatable", dt); } //bind gridview GridView1.DataSource = dt; GridView1.DataBind(); }
makhaai
modified on Thursday, June 10, 2010 5:06 PM