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. DataGrid binding and Viewstate problem

DataGrid binding and Viewstate problem

Scheduled Pinned Locked Moved ASP.NET
helpdatabasewpfwcfquestion
8 Posts 3 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.
  • L Offline
    L Offline
    lupin68
    wrote on last edited by
    #1

    Hi folks, here's the problem I have been stuck on: After I modify a row in my Datagrid, I want to reload just the row that was modified. I still want to issue a DataBind but I dont want to get the entire list that is displayed in the Datagrid. Just Update the row that was modified. The reason for that is that the datagrid can display a different list based on different searches that the user submits. So when the Modify button is pressed (the modify button is not an ItemCommand), I cannot do a databind based on what his initial search was, because I don't know what parameters to pass(to the query). Someone told me I could use the ViewState to store my DG and the issue a rebind. Is this possible? How would it work? Thanks for ANY help. :(( Patrick

    F P 2 Replies Last reply
    0
    • L lupin68

      Hi folks, here's the problem I have been stuck on: After I modify a row in my Datagrid, I want to reload just the row that was modified. I still want to issue a DataBind but I dont want to get the entire list that is displayed in the Datagrid. Just Update the row that was modified. The reason for that is that the datagrid can display a different list based on different searches that the user submits. So when the Modify button is pressed (the modify button is not an ItemCommand), I cannot do a databind based on what his initial search was, because I don't know what parameters to pass(to the query). Someone told me I could use the ViewState to store my DG and the issue a rebind. Is this possible? How would it work? Thanks for ANY help. :(( Patrick

      F Offline
      F Offline
      fadee
      wrote on last edited by
      #2

      well, yup its quite easy to do so :) Now how to use it... just locate the position where you have written logic to perform the search and load the dataset. At this point, just insert the dataset or datatable into viewstate. Now in that event, just push back the dataset. You will have it all :) // Inserting a datatable into view state viewstate.Add("KEY", ds.Tables("SearchResults")) // Getting the dataset back dt = viewstate("KEY") datagrid.DataSource = dt datagrid.DataBind() But remember, viewstate increases the response dynamically and increases the response time. mE! ------------------- Therez No Place like ... 127.0.0.1

      1 Reply Last reply
      0
      • L lupin68

        Hi folks, here's the problem I have been stuck on: After I modify a row in my Datagrid, I want to reload just the row that was modified. I still want to issue a DataBind but I dont want to get the entire list that is displayed in the Datagrid. Just Update the row that was modified. The reason for that is that the datagrid can display a different list based on different searches that the user submits. So when the Modify button is pressed (the modify button is not an ItemCommand), I cannot do a databind based on what his initial search was, because I don't know what parameters to pass(to the query). Someone told me I could use the ViewState to store my DG and the issue a rebind. Is this possible? How would it work? Thanks for ANY help. :(( Patrick

        P Offline
        P Offline
        payback
        wrote on last edited by
        #3

        hi, U can do it this way. u can put the search parameter in a ViewState variable with wich the grid was populated. ViewState("SearchParameter") = "_msg_date" Then after saving modification in the database u can reload the grid with the search parameter that user provided stored in the ViewState. BindGrid(CStr(ViewState("SearchParameter"))) Well u can also Put the whole DataTable in the ViewState but it can raise some performance issue depending on the size of DataTable.try it..... PayBack

        F L 2 Replies Last reply
        0
        • P payback

          hi, U can do it this way. u can put the search parameter in a ViewState variable with wich the grid was populated. ViewState("SearchParameter") = "_msg_date" Then after saving modification in the database u can reload the grid with the search parameter that user provided stored in the ViewState. BindGrid(CStr(ViewState("SearchParameter"))) Well u can also Put the whole DataTable in the ViewState but it can raise some performance issue depending on the size of DataTable.try it..... PayBack

          F Offline
          F Offline
          fadee
          wrote on last edited by
          #4

          Thats excellent solution :) I recomend this one coz viewstate size will remain within reasonable limits. I was thinking about this but don know why I never suggested this :) Have Fun. mE! ------------------- Therez No Place like ... 127.0.0.1

          1 Reply Last reply
          0
          • P payback

            hi, U can do it this way. u can put the search parameter in a ViewState variable with wich the grid was populated. ViewState("SearchParameter") = "_msg_date" Then after saving modification in the database u can reload the grid with the search parameter that user provided stored in the ViewState. BindGrid(CStr(ViewState("SearchParameter"))) Well u can also Put the whole DataTable in the ViewState but it can raise some performance issue depending on the size of DataTable.try it..... PayBack

            L Offline
            L Offline
            lupin68
            wrote on last edited by
            #5

            Thanks guys, PayBack, this sounds great but I am not quite sure I understand how to do it. By the way, I don't use a DataTable, nor a DataSet. My search (let's say OrderNo.) goes like this { Order order = new Order(); ArrayList ordernumber = order.GetOrders(txtOrderno.Text, etc...) DataGrid.DataSource = ordernumber; DataGrid.DataBind(); } For another search (let's say the Customer ID), the ArrayList would be populated using a different method. The DB query (Storedprocedure) is called in another CS called by the GetOrders method. I am not sure how I could apply the ViewState("SearchParameter") = "_msg_date" in this context. Thanks again

            P 1 Reply Last reply
            0
            • L lupin68

              Thanks guys, PayBack, this sounds great but I am not quite sure I understand how to do it. By the way, I don't use a DataTable, nor a DataSet. My search (let's say OrderNo.) goes like this { Order order = new Order(); ArrayList ordernumber = order.GetOrders(txtOrderno.Text, etc...) DataGrid.DataSource = ordernumber; DataGrid.DataBind(); } For another search (let's say the Customer ID), the ArrayList would be populated using a different method. The DB query (Storedprocedure) is called in another CS called by the GetOrders method. I am not sure how I could apply the ViewState("SearchParameter") = "_msg_date" in this context. Thanks again

              P Offline
              P Offline
              payback
              wrote on last edited by
              #6

              Hello, well this depends on the scenario.if we talk abt the code u paste. The ArryList will always be populated from ViewState Variable and u Set the ViewState on the event where u allows the User to Change the search. ViewState("OrderNumber") = txtOrderno.Text Now u Bind the grid with ViewState. { Order order = new Order(); ArrayList ordernumber = order.GetOrders(ViewState("OrderNumber"), etc...) DataGrid.DataSource = ordernumber; DataGrid.DataBind(); } The Basic idea is to get the Grid Populated with the last Criteria used before the server trip. PayBack

              L 1 Reply Last reply
              0
              • P payback

                Hello, well this depends on the scenario.if we talk abt the code u paste. The ArryList will always be populated from ViewState Variable and u Set the ViewState on the event where u allows the User to Change the search. ViewState("OrderNumber") = txtOrderno.Text Now u Bind the grid with ViewState. { Order order = new Order(); ArrayList ordernumber = order.GetOrders(ViewState("OrderNumber"), etc...) DataGrid.DataSource = ordernumber; DataGrid.DataBind(); } The Basic idea is to get the Grid Populated with the last Criteria used before the server trip. PayBack

                L Offline
                L Offline
                lupin68
                wrote on last edited by
                #7

                Neat! thx PayBack works well.;)

                P 1 Reply Last reply
                0
                • L lupin68

                  Neat! thx PayBack works well.;)

                  P Offline
                  P Offline
                  payback
                  wrote on last edited by
                  #8

                  Thanks Guys :)

                  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