using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGridView(); } } protected void BindGridView() { DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter("Select eid,ename,age from emp", con); con.Open(); da.Fill(dt); con.Close(); if (dt.Rows.Count > 0) { GridView1.DataSource = dt; GridView1.DataBind(); } } protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { TextBox txt_name = new TextBox(); TextBox txt_age = new TextBox(); TextBox txt_id = new TextBox(); txt_id = (TextBox)GridView1.FooterRow.FindControl("txt_eid"); txt_name = (TextBox)GridView1.FooterRow.FindControl("txt_ename"); txt_age = (TextBox)GridView1.FooterRow.FindControl("txt_eage"); SqlCommand cmd = new SqlCommand("insert into emp(eid,ename,age)values('" + txt_id.Text + "','" + txt_name.Text + "','" + txt_age.Text + "')"); con.Open(); cmd.ExecuteNonQuery(); con.Close(); BindGridView(); } }
NullReference
TextBoxes
null
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)