Click here to Skip to main content
14,336,453 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello all
i have newly moved from webforms to winforms. My problem is I cant find an equivalent to a gridview's databind method in order to refresh the datasource. here is my scenario if it helps:
I have a datagrid that displays data from a table and a form that inserts a new record into the same table. what i want is when the user inserts a new record, it should directly show in the datagrid without the need of closing and re-opening the form to see the updated data
A fairly detailed guidance would be proffered and very appreciated
Many thanks :)
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Please understand the idea behind this
//Make a common method to call one more times
void BindDataGridView()
{
    DataTable mydata = GetDataFromDatabase();//Get your data from database
    DataGridView1.DataSource = mydata;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
    string insertQuery = "write your insert query";
    Dal.InsertData(insertQuery);//Insert your record to database
    BindDataGridView();//Again call your bind method to display inserted data in datagridview
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100