Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

 
Share this answer
 
Please understand the idea behind this
C#
//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
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900