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
Govinda Rajulu YemineniPosted Jul 9, 2015, 5:42 AM
ajeet vermaPosted Jul 9, 2015, 4:04 AM
ajeet vermaPosted Jul 9, 2015, 4:04 AM
Amit ChoudharyPosted Nov 26, 2009, 1:04 AM
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
Nilanka DharmadasaPosted Nov 26, 2009, 1:02 AM
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.
roy himanshuPosted Nov 26, 2009, 12:38 AM
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 DharmadasaPosted Nov 26, 2009, 12:36 AM
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.
Lalit MPosted Nov 26, 2009, 12:22 AM
More info also you can visit this link .