Note that there are some explanatory texts on larger screens.

plurals
  1. POGridview paging in c#, dynamic SQL query
    primarykey
    data
    text
    <p>I am new to c#, using Visual Studio 2010.</p> <p>I created a grid view and enabled paging. It works fine with all the data. </p> <p>But I have few drop downs and filter buttons at the top of the page. When I press each filter buttons the grid view show filtered data only. </p> <p>I wrote each SQL statement for the button click events. </p> <p>Suppose that I have 60 records and grid view shows 10 record per page. When I click filter button and suppose it shows only 25 records. That means there is only 3 pages showing. That is ok and works. But when I click second or third page it will again show all the data, that means 5 pages. </p> <p>I know the problem is it run the default SQL query (that I use to bind data to grid view in graphical mood). But I need to know how to fix it. I only need to do is show each page without changing the filtered data.</p> <p>Here is my grid view code:</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="DocumentID" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged" style="font-family: Tahoma; font-size: small; text-align: center;" Width="100%" AllowPaging="True" AllowSorting="True" onpageindexchanging="GridView1_PageIndexChanging"&gt; &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="DocumentID" HeaderText="Document ID" InsertVisible="False" ReadOnly="True" SortExpression="DocumentID" /&gt; &lt;asp:BoundField DataField="DocumentType" HeaderText="Document Type" SortExpression="DocumentType" /&gt; &lt;asp:BoundField DataField="ReceivedDate" HeaderText="Received Date" SortExpression="ReceivedDate" DataFormatString="{0:dd/MM/yyyy}" /&gt; &lt;asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /&gt; &lt;asp:CommandField SelectText="&amp;gt;&amp;gt;" ShowSelectButton="True" /&gt; &lt;/Columns&gt; &lt;EditRowStyle BackColor="#999999" /&gt; &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerSettings PageButtonCount="5" Mode="NumericFirstLast" /&gt; &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt; &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt; &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt; &lt;SortedAscendingCellStyle BackColor="#E9E7E2" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#506C8C" /&gt; &lt;SortedDescendingCellStyle BackColor="#FFFDF8" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE" /&gt; &lt;PagerSettings Mode="NumericFirstLast" PageButtonCount="10" FirstPageText="First" LastPageText="Last"/&gt; &lt;/asp:GridView&gt; </code></pre> <p>and my <code>pageindexchanging</code> is</p> <pre><code> protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; //GridView1.DataBind(); } </code></pre> <p>and here is my <code>SqlDataSource</code></p> <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" SelectCommand="SELECT InwardDetails.DocumentID, InwardDetails.Title, DocumentTypeDetails.DocumentType, InwardDetails.ReceivedDate FROM InwardDetails INNER JOIN DocumentTypeDetails ON InwardDetails.DocumentType = DocumentTypeDetails.DocumentTypeID"&gt; &lt;/asp:SqlDataSource&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload