GridView not Updating
-
Hi All I created a web page on which I have a GridView. I took AccessDataSource as GridView's DataSource. On selection changing Event of gridview, I redirect selected Row's data to other form where User can Edit and get back to previous page. Its my need that I hve to redirect to new page for editing not in the GridView itself. Everything working fine but After Editing when I returned to GridView page, the GridView is not updated, It requres Refresh(f5) to show updated gridview. I tried GridView.DataBind() using IsPostBack but no benefit. Please Guide me , Thanks
protected void Page_Load(object sender, EventArgs e) { mydb = new myDB(); if (mydb.Conn.State == ConnectionState.Closed) mydb.Conn.Open(); if (!IsPostBack) { if (Request.QueryString["GridIndex"] != null) { int GVIndex = Convert.ToInt32(Request.QueryString["GridIndex"]); string sortingField = Request.QueryString["SortingField"]; string sortingOrder = Request.QueryString["SortingOrder"]; SortDirection sd = new SortDirection(); if (!sortingField.Equals("")) { if (sortingOrder.Equals("Ascending")) { sd = SortDirection.Ascending; GVRackMaster.Sort(sortingField, sd); } else { sd = SortDirection.Descending; GVRackMaster.Sort(sortingField, sd); } } GVRackMaster.PageIndex = GVIndex; GVRackMaster.DataBind(); } } GVRackMaster.DataBind(); }
Bajrang Singh Using .net 2.0 (VS2005)
-
Hi All I created a web page on which I have a GridView. I took AccessDataSource as GridView's DataSource. On selection changing Event of gridview, I redirect selected Row's data to other form where User can Edit and get back to previous page. Its my need that I hve to redirect to new page for editing not in the GridView itself. Everything working fine but After Editing when I returned to GridView page, the GridView is not updated, It requres Refresh(f5) to show updated gridview. I tried GridView.DataBind() using IsPostBack but no benefit. Please Guide me , Thanks
protected void Page_Load(object sender, EventArgs e) { mydb = new myDB(); if (mydb.Conn.State == ConnectionState.Closed) mydb.Conn.Open(); if (!IsPostBack) { if (Request.QueryString["GridIndex"] != null) { int GVIndex = Convert.ToInt32(Request.QueryString["GridIndex"]); string sortingField = Request.QueryString["SortingField"]; string sortingOrder = Request.QueryString["SortingOrder"]; SortDirection sd = new SortDirection(); if (!sortingField.Equals("")) { if (sortingOrder.Equals("Ascending")) { sd = SortDirection.Ascending; GVRackMaster.Sort(sortingField, sd); } else { sd = SortDirection.Descending; GVRackMaster.Sort(sortingField, sd); } } GVRackMaster.PageIndex = GVIndex; GVRackMaster.DataBind(); } } GVRackMaster.DataBind(); }
Bajrang Singh Using .net 2.0 (VS2005)
After removing your if(!=PostBack) block the following is left; protected void Page_Load(object sender, EventArgs e) { mydb = new myDB(); if (mydb.Conn.State == ConnectionState.Closed) { mydb.Conn.Open(); } GVRackMaster.DataBind(); } It appears that after the first time the page loads, your not updating your datasource. That would explian why you don't see the update unless you reload the whole page. BTW, you should ad something to ensure that the mydb.Conn is closed when your done, just in case. Hope this helps!
-
After removing your if(!=PostBack) block the following is left; protected void Page_Load(object sender, EventArgs e) { mydb = new myDB(); if (mydb.Conn.State == ConnectionState.Closed) { mydb.Conn.Open(); } GVRackMaster.DataBind(); } It appears that after the first time the page loads, your not updating your datasource. That would explian why you don't see the update unless you reload the whole page. BTW, you should ad something to ensure that the mydb.Conn is closed when your done, just in case. Hope this helps!
Thanks mnvkng76 for Reply. I am using AccessDataSource as DataSource of GridView. So when I update the Table RackMAster, AccessDataSource is updated automatically. So where is the need of updating DataSource. Second thing I don't know where Should i write code for closing the connection, PLease tell me. Although I changed my connection code to protected void Page_Load(object sender, EventArgs e) { if (mydb.Conn.State == ConnectionState.Open) { mydb.Conn.Close(); } mydb.Conn.Open(); } But problem remains the same. AccessDataSource has nothing to do with mydb because I made AccessDataSource in design time so I don't thinks mydb can affect accessDataSource. Is there any way to Refresh AccessDataSource. Hope to get a solution from u earliest. Thanks Bye
Bajrang Singh Using .net 2.0 (VS2005)
-
Thanks mnvkng76 for Reply. I am using AccessDataSource as DataSource of GridView. So when I update the Table RackMAster, AccessDataSource is updated automatically. So where is the need of updating DataSource. Second thing I don't know where Should i write code for closing the connection, PLease tell me. Although I changed my connection code to protected void Page_Load(object sender, EventArgs e) { if (mydb.Conn.State == ConnectionState.Open) { mydb.Conn.Close(); } mydb.Conn.Open(); } But problem remains the same. AccessDataSource has nothing to do with mydb because I made AccessDataSource in design time so I don't thinks mydb can affect accessDataSource. Is there any way to Refresh AccessDataSource. Hope to get a solution from u earliest. Thanks Bye
Bajrang Singh Using .net 2.0 (VS2005)
Closng the connection wont fix, the problem. Its just good practice to ensure that all your connection are closed when they are not needed. It prevents other problems. Without seeing more of the code, it would be tough to debug further. Even though your working with a datasource created at design time, it still loads at runtime, so maybe the issue lies there.