Hi how can i persist gridview data after crosspage posting? It seems that every time i visit another page and get back to page the entire gridview data and page index were reset.
Printable View
Hi how can i persist gridview data after crosspage posting? It seems that every time i visit another page and get back to page the entire gridview data and page index were reset.
are you binding the gridview with data in the page load event?
jlbantang,
When you say visit another page and get back to page, how exactly are you handling this navigation? Through code, or through the user using the back button in their browser?
I think you are going to need to show us some of the code that you are using before we will be able to help you.
Gary
hey,
The purpose of gridview will allow user to filter data. For each filtered row a hyperlinked button is added which in turn use by user to navigate to other page.
vb Code:
<div> <img src="Images/logo1.gif" /> <br /> <br /> <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/requisition.aspx">Requisition</asp:HyperLink> <asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="~/requestworkflow.aspx">Request Workflow</asp:HyperLink> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/new_delivery.aspx">New Delivery</asp:HyperLink> <asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/stockcard.aspx">Stock Card</asp:HyperLink> <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/contactus.aspx">Contact Us</asp:HyperLink><br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None"> <Columns> <asp:HyperLinkField DataNavigateUrlFields="ID,pk_ddlvryNO,lpono" DataNavigateUrlFormatString="edit_delivery.aspx?id={0}" Text="<img src='Images/edit.gif' alt='Edit' border='0'/>" /> <asp:BoundField DataField="pk_ddlvryNO" HeaderText="Delivery No" SortExpression="pk_ddlvryNO" /> <asp:BoundField DataField="entereddate" HeaderText="Dated" SortExpression="entereddate" /> <asp:BoundField DataField="pk_RFGNO" HeaderText="Requisition No" SortExpression="pk_RFGNO" /> <asp:BoundField DataField="lpono" HeaderText="LPO No" SortExpression="lpono" /> <asp:BoundField DataField="lpodate" HeaderText="Dated" SortExpression="lpodate" /> <asp:BoundField DataField="supplier" HeaderText="Supplier" SortExpression="suplier" /> <asp:BoundField DataField="invno" HeaderText="Invoice No" SortExpression="invno" /> <asp:BoundField DataField="invdate" HeaderText="Dated" SortExpression="invdate" /> </Columns> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#999999" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView> <asp:DropDownList ID="criteriaDropDownList" runat="server"> <asp:ListItem>ALL</asp:ListItem> <asp:ListItem>Delivery No</asp:ListItem> <asp:ListItem>Requisition No</asp:ListItem> <asp:ListItem>LPO No</asp:ListItem> <asp:ListItem>Invoice No</asp:ListItem> <asp:ListItem>Supplier</asp:ListItem> </asp:DropDownList> <asp:TextBox ID="valueTextBox" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/img/edit.gif" /><br /> Theme Color<br /> <img src="Images/search_bg.gif" /><br /> <br /> | <br /> <br /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>" SelectCommand="Select pk_ddlvryMasterID as ID ,pk_ddlvryNO , convert(varchar,entereddate,106) as entereddate ,pk_rfgNO,lpono, convert(varchar,lpodate,106) as lpodate,Supplier,invno, convert(varchar,invdate,106) as invdate from qDDlvryMaster"> </asp:SqlDataSource> </div>
vb Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim filter As String = "Select pk_ddlvryMasterID as ID ,pk_ddlvryNO " filter += ", convert(varchar,entereddate,106) as entereddate" filter += ",pk_rfgno,lpono, convert(varchar,lpodate,106) as lpodate" filter += ",Supplier,invno, convert(varchar,invdate,106) as invdate" filter += " from qDDlvryMaster " Dim criteria As String = String.Empty Select Case criteriaDropDownList.Text.ToUpper Case "DELIVERY NO" : criteria = "pk_ddlvryNO" Case "REQUISITION NO" : criteria = "pk_rfgno" Case "LPO NO" : criteria = "lpono" Case "INVOICE NO" : criteria = "invno" Case "SUPPLIER" : criteria = "supplier" End Select 'TODO add cost centre id If criteriaDropDownList.Text <> "ALL" Then SqlDataSource1.SelectCommand = filter & " WHERE " & criteria & " like '%" & valueTextBox.Text & "%' ORDER BY pk_ddlvryMasterID DESC" Else SqlDataSource1.SelectCommand = filter & " ORDER BY pk_ddlvryMasterID DESC" End If GridView1.DataBind() End Sub Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex GridView1.DataBind() End Sub
But you still haven't explained how it is that they get back to the filtered GridView?
It might be the case that you need to store the "filter" in a Session Variable, and use this "filter" value to setup the GridView once a users navigates back to the same page.
Gary
So are you dynamically setting the NavigateUrl property of the Hyperlink, or is this fixed? Another way would be to provide a QueryString parameter on the Hyperlink button, that is then read in on the other page to provide the "filter" for the GridView.
Gary