Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. GridView not Updating

GridView not Updating

Scheduled Pinned Locked Moved ASP.NET
csharptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bajrang Singh
    wrote on last edited by
    #1

    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)

    M 1 Reply Last reply
    0
    • B Bajrang Singh

      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)

      M Offline
      M Offline
      mnvkng76
      wrote on last edited by
      #2

      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!

      B 1 Reply Last reply
      0
      • M mnvkng76

        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!

        B Offline
        B Offline
        Bajrang Singh
        wrote on last edited by
        #3

        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)

        M 1 Reply Last reply
        0
        • B Bajrang Singh

          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)

          M Offline
          M Offline
          mnvkng76
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups