I have below gridview and sqldatasource.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
" DataKeyNames="AccountID"
DataSourceID="SqlDataSourc
e1" AllowPaging="True" PageSize="2" CellPadding="4"
ForeColor="#333333" GridLines="None" EmptyDataText="No results returned" EnableSortingAndPagingCall
backs="Tru
e">
<Columns>
<asp:BoundField DataField="AccountID" HeaderText="AccountID" InsertVisible="False"
ReadOnly="True" SortExpression="AccountID"
Visible="False" />
<asp:BoundField DataField="UserID" HeaderText="User ID" SortExpression="UserID" />
<asp:BoundField DataField="FullName" HeaderText="Name" SortExpression="FullName" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="CompanyName" HeaderText="Company" SortExpression="CompanyNam
e" />
<asp:BoundField DataField="T1" HeaderText="T1" SortExpression="T1" />
<asp:BoundField DataField="T2" HeaderText="T2" SortExpression="T2" />
<asp:BoundField DataField="T3" HeaderText="T3" SortExpression="T3" />
<asp:BoundField DataField="BT" HeaderText="BT" SortExpression="BT" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
</Columns>
<PagerSettings Position="Top" Mode="NumericFirstLast" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Right" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CaasConn
ectionStri
ng %>"
SelectCommand="Select AccountID, UserID, FullName, Case RoleType When 0 Then 'Admin' Else 'User' End 'Role', t2.CompanyName, Case T1 When 1 Then 'Y' Else 'N' End 'T1', Case T2 When 1 Then 'Y' Else 'N' End 'T2', Case T3 When 1 Then 'Y' Else 'N' End 'T3', Case BT When 1 Then 'Y' Else 'N' End 'BT', Case t1.Status When 1 Then 'Active' Else 'Disabled' End 'Status'
From tblAccount t1 Inner Join tblCompany t2 On t1.CompanyID = t2.CompanyID
Where 1 = 0
Order By UserID"></asp:SqlDataSourc
e>
I also have a submit button. On submit, I will build a sql statement dynamically and rebind the gridview as below.
protected void btnSearch_Click(object sender, EventArgs e)
{
///////
SqlDataSource1.SelectComma
nd = sql;
SqlDataSource1.SelectComma
ndType = SqlDataSourceCommandType.T
ext;
GridView1.DataBind();
}
All works but problem arises when I click on next page index of gridview. I enable paging for my datagrid. On click of another page index, no results is returned by the datasouce. How come?