Text box values post to grid

Posted by Riasul under C# on 6/24/2010 | Views : 3859 | Status : [Member] | Replies : 3
Hi,
I am writing the following code in c# windows applications.i want to display textbox value to datagrid.
the following code display first value to grid.i want to display all entered textbox value to gridview.this code display only last entered value.any one help me please

private void button1_Click(object sender, EventArgs e)
{

DataTable dt = new DataTable();
dt.Columns.Add("SNo");
dt.Columns.Add("Name");
dt.Columns.Add("Age");
dt.Columns.Add("Country");

dr = dt.NewRow();
dr["Name"] = textBox1.Text;
dr["Age"] = textBox2.Text;
dr["Country"] = textBox3.Text;
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";

}




Responses

Posted by: Vuyiswamb on: 6/25/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
I am not sure what you want exactly. i have written an article Years ago to manupilate the Datagrid.
http://www.codeproject.com/KB/cs/N-Tier22.aspx

Can you explain a little bit better ?

Thank you for posting at Dotnetfunda
[Administrator]

Riasul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/13/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Riasul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 7/29/2010 [Member] Bronze

Up
0
Down
You can achieve this by declaring the DataTable at global and make the datatable in ViewState, so it won't change the details when page gets refreshed.

Riasul, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response