المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to insert data into a GridView from the textboxes



C# Programming
10-20-2009, 09:00 PM
Hi all,

I have a Grid view on my page and I need it displayed on Page Load with only the column names. I then need to save data into the Grid view with values for the textboxes after clicking ADD button.

This is what I have but it doesn't do what I want to it to do.

Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
this.dgInfoProfile.DataSource = dt;
dgInfoProfile.DataBind();

}



ADD button:
protected void brtAdd_Click(object sender, EventArgs e)
{
try
{
////DataTable dt = new DataTable();
DataRow dr = dt.NewRow();
dr["Full Names"] = txtFirstName3.Text;
dr["Identifying Number"] = txtIdentityNo.Text;
dr["Passport Number"] = txtPassportNo.Text;
dt.Rows.Add(dr);

////Bind GridView Here with this Table
this.dgInfoProfile.DataSource = dt;
dgInfoProfile.DataBind();

}
catch (Exception ex)
{
Response.Write(ex.Message);
}

} http://www.barakasoft.com/script/Forums/Images/smiley_confused.gifhttp://www.barakasoft.com/script/Forums/Images/smiley_confused.gif

if you have any idea on how to get this done, I'd really appreciate your advise.

Thanks.