.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
bind();
}
}
private void bind()
{
string strcon="Data Source=(local);Initial Catalog=text;User ID=sa;Password=sa123";
string strsql = "SELECT Card,UserName,Sex,Address FROM UserInfo";
SqlDataAdapter da = new SqlDataAdapter(strsql, strcon);
DataTable dt = new DataTable();
da.Fill(dt);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
TextBox txtCard = GridView1.FooterRow.Cells[0].FindControl("txtCard") as TextBox;
TextBox txtUserName=GridView1.FooterRow.Cells[1].FindControl("txtUserName")as TextBox;
TextBox txtSex=GridView1.FooterRow.Cells[2].FindControl("txtSex")as TextBox;
TextBox texAddress=GridView1.FooterRow.Cells[3].FindControl("texAddress")as TextBox;
Response.Write("txtCard:" + txtCard.Text + "<br/>");
Response.Write("txtUserName:" + txtUserName.Text + "<br/>");
Response.Write("txtSex:" + txtSex.Text + "<br/>");
Response.Write("texAddress:" + texAddress.Text + "<br/>");
txtCard.Text = "";
txtUserName.Text = "";
txtSex.Text = "";
texAddress.Text = "";
}