Click here to Skip to main content
15,902,939 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:GridView ID="gvBC" runat="server" AutoGenerateColumns="False" ShowFooter="True" AllowSorting="True" AllowPaging="True" pageSize ="3" DataSourceID="dsBCSearch">
        <asp:BoundField DataField="ContactID" HeaderText="ContactID" Visible="false"/>
        <asp:BoundField DataField="BldgNum" HeaderText="Bldg#" SortExpression="BldgNum" />
    <EmptyDataTemplate> No Building Coordinator Found. </EmptyDataTemplate>
    <EmptyDataRowStyle HorizontalAlign="Center" /> 
<asp:SqlDataSource ID="dsBCSearch" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnStr %>" SelectCommand="GetBC" SelectCommandType="StoredProcedure" 
SortParameterName="SortExpression"  />

Code behind:

protected void Page_Load(object sender, EventArgs e)
protected void LoadBC()
    dsBCSearch.SelectCommand = "GetBCwP";

    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());


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

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[^]
Share this answer
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