I am inserting data to database when i click submit button data inserted into Database but no changes get reflected in GridView without refreshing the page. I used DataBind() also.
Asked
Active
Viewed 1.8k times
1
-
see this http://stackoverflow.com/questions/7409339/refresh-gridview-after-adding-or-deleting-new-record-in-c-sharp – nKandel Sep 20 '12 at 17:25
-
1You should show some code when you ask questions like this. It would be a lot easier to help with an appropriate answer. – slfan Sep 22 '12 at 15:48
5 Answers
2
it is enough to add
YourGridView.DataBind();
in your button onclick event.... no need to bind it also in Page_Load
Do you have any updatepanels?

avi
- 912
- 8
- 22
1
Just use the Procedure which populates the GridView and then call that Procedure OnClick Event.
Hope it Helps

عثمان غني
- 2,786
- 4
- 52
- 79
0
You can use this code - based on DataBind
two times
Nota : you add this DataBind no just in your Page_Load but also in your delegate of click
//Your Insert in your delegate
....
YourGridView.DataBind();

Aghilas Yakoub
- 28,516
- 5
- 46
- 51
0
You have to refresh the gridviews data source through whatever means your using, for instance an sql query and then set the datasource to this and then use Gridview1.DataBind();
public void GetData()
{
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = ConfigurationManager.ConnectionStrings["mysql"].ConnectionString;
String sql = "Your Query";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, connection);
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
GridView1.DataSource = dt;
}
catch (SqlException ex)
{
}
catch (Exception e)
{
}
}
Then just use GetData() before you bind the gridview (possibly in your page load event).

Wadester
- 453
- 4
- 12
0
You can also do in your rowCommand:
gridView_RowCommand(object sender, GridViewCommandEventArgs e){
gridView.EditIndex = -1; // to cancel edit mode
}

Arun Vinoth-Precog Tech - MVP
- 22,364
- 14
- 59
- 168