How to insert text in GridView ?
-
I want to insert text in gridview but i dont have any data source. How can I insert text values in dataGridview? for example if i want to insert value in textbox i will user textBox1.text="Adfsr" like in the same way i want to create a gridview i have two columns viz Name and description in datagridview and I want to insert in "Arun" in name field and "Healthy person" in description. please suggest. I want to use dataGridview only....
Arun Singh Noida.
-
I want to insert text in gridview but i dont have any data source. How can I insert text values in dataGridview? for example if i want to insert value in textbox i will user textBox1.text="Adfsr" like in the same way i want to create a gridview i have two columns viz Name and description in datagridview and I want to insert in "Arun" in name field and "Healthy person" in description. please suggest. I want to use dataGridview only....
Arun Singh Noida.
First You should take 2 textboxes and one button.. then write the following code Globally.... static DataSet ds = new DataSet(); static DataTable dt=new DataTable(); and in pageload event you should paste this code if(!IsPostBack) { dt.Columns.Clear(); ds.Clear(); dt.Rows.Clear(); dt.Columns.Add("Name"); dt.Columns.Add("Number"); ds.Tables.Clear(); ds.Tables.Add(dt); DataGrid1.DataSource =ds; DataGrid1.DataBind(); } and Write code for button1.. DataRow r=dt.NewRow(); r[0]=TextBox1.Text; r[1]=TextBox2.Text; ds.Tables[0].Rows.Add(r);// dt.Rows.Add(r); DataGrid1.DataSource =ds; DataGrid1.DataBind();
venki