Click here to Skip to main content
15,118,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need use sqldatasource(stored proc) to bind a gridview.

ASP.NET
<asp:GridView ID="gvBC" runat="server" AutoGenerateColumns="False" ShowFooter="True" AllowSorting="True" AllowPaging="True" pageSize ="3" DataSourceID="dsBCSearch">
    <Columns>
        <asp:BoundField DataField="ContactID" HeaderText="ContactID" Visible="false"/>
        <asp:BoundField DataField="BldgNum" HeaderText="Bldg#" SortExpression="BldgNum" />
    </Columns>
    <EmptyDataTemplate> No Building Coordinator Found. </EmptyDataTemplate>
    <EmptyDataRowStyle HorizontalAlign="Center" /> 
</asp:GridView>
<asp:SqlDataSource ID="dsBCSearch" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnStr %>" SelectCommand="GetBC" SelectCommandType="StoredProcedure" 
SortParameterName="SortExpression"  />


Code behind:

C#
protected void Page_Load(object sender, EventArgs e)
{
    LoadBC();
}
protected void LoadBC()
{
    dsBCSearch.SelectCommand = "GetBCwP";
    dsBCSearch.SelectParameters.Clear();

    dsBCSearch.SelectParameters.Add("LName", this.txtLNAme.Text.Trim());
    dsBCSearch.SelectParameters.Add("Active", this.chkActive.Checked.ToString());
    //dsBCSearch.SelectParameters.Add("sortExpression", this.gvBC.SortExpression);
    dsBCSearch.SelectParameters.Add("startRowIndex", this.gvBC.PageIndex.ToString());
    dsBCSearch.SelectParameters.Add("maximumRows", this.gvBC.PageSize.ToString());

    this.gvBC.DataBind();
}

Now just render first page (3 records) and in footer no number showing up. HOw can I add paging to footer?

Thanks
Posted
Comments
Richard C Bishop 1-May-13 16:28pm
   
How many records do you have in the database?
lmik9898 1-May-13 17:35pm
   
600 records

1 solution

Have a look in this link it might help you.
Optimized Paging and Sorting using Object Data Source[^]
   
Comments
lmik9898 2-May-13 9:04am
   
Thanks a lot. But ObjectDataSource is easy with the custom paging, but SqlDataSource is another story.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900