Question

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">
    <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:

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

Was it helpful?

Solution

sqldatasource is not good for custom paging. I have to add another pager part and like old asp page, to manually write the code. But objectdatasource is much easy for this. It will have some parameter like StartRowIndexParameterName MaximumRowsParameterName SortParameterName SelectCountMethod. It will auto pass to data souce

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top