hi,
iam working on windows application,in my form contains one text box and data gridview and one save button.when i enterd one item in text box and click save button then the record is saved in grid view first row.I know this way. but i want next time i entered second item in text box,click save button then the record is saved in gridviews second row.my requirement is in first row first record,second row second record both are displayed.but only one record displayed in grid view.how is both rtecord displayed.is it possible.plz help
Loading

Lalit MRank #1,186 · 1.5K reputationPosted Nov 25, 2009, 7:22 PM EST
More info also you can visit this link .
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 25, 2009, 7:36 PM EST
Friend, your problem is not so clear for me. Have you bound a datasource to your datagrid view? Or you just want to display the textyou entered in text box in data grid view?
If you can paste your code here, i can easily help you.
roy himanshu98 reputationPosted Nov 25, 2009, 7:38 PM EST
i want to add a new row to the data gridview on clicking a button . how can i do it in c#.plz help
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 25, 2009, 8:02 PM EST
You can do it using following code.
If you have only one column defined in your datagridview then following code will do what you want.
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Add(textBox1.Text);
}
If you have two columns then pass two values.
dataGridView1.Rows.Add(textBox1.Text, "value2");
Please mark Do you like this answer checkbox, if this helps you.
Amit ChoudharyRank #145 · 15.8K reputationPosted Nov 25, 2009, 8:04 PM EST
There is two way of doing this if want to save that row to database too then just save it using your approach to save the data to DB and then ReBind the GridView....
GridView1.DataSource=ds;
GridView1.DataBind();
another is you dont want to save the row to database just want to display it on the grid then...
Go to this article its on C-sharp corner it self.. and dont forget to mark the answer if it help you... :)
http://www.c-sharpcorner.com/UploadFile/Art%20Scott/GridViewInsertANewRow09012006165053PM/GridViewInsertANewRow.aspx
ajeet verma21 reputationPosted Jul 9, 2015, 12:04 AM EDT
ajeet verma21 reputationPosted Jul 9, 2015, 12:04 AM EDT
Govinda Rajulu YemineniRank #1,518 · 1K reputationPosted Jul 9, 2015, 1:42 AM EDT