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