2013-05-01 62 views
1

我需要使用sqldatasource(存儲過程)來綁定gridview。背後SqlDataSource自定義分頁

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

代碼:

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

現在只呈現第一頁(3條)和頁腳沒有號碼顯示出來。你可以給頁腳添加分頁嗎?

謝謝

回答

1

sqldatasource不適合自定義分頁。我必須添加另一個尋呼機部件,並像老的asp頁面一樣手動編寫代碼。 但是objectdatasource對此很容易。它將有一些參數,如StartRowIndexParameterName,MaximumRowsParameterName,SortParameterName,SelectCountMethod。它會自動傳遞到數據源