4

以下のコードは、PagerSetting を削除するかPagerTemplateを削除すると正常に動作するため、両方 ( PagerSettingPagerTemplate ) がある場合、ページ番号は表示されません。

私の質問は: Gridview の下部に両方( PagerTemplate と PagerSetting ) を一緒に表示するにはどうすればよいですか? 以下のソースコードをご覧ください。

<asp:GridView ID="gvTable" runat="server" ShowHeader="true"     
  PageSize="5" AllowPaging="true" AllowSorting="true"     
  DataSourceID="myLinqDataSource" AutoGenerateColumns="false"     
  OnRowDataBound="GridView_DataBound">     
  <Columns>     
    <asp:BoundField DataField="Edited" HeaderText="Date" DataFormatString="{0:d}" />     
    <asp:BoundField DataField="Activity" HeaderText="Notes" />     
  </Columns>     
<PagerStyle CssClass="pager-row" />    
                    <RowStyle CssClass="row" />    
                    <PagerSettings Mode="NumericFirstLast" PageButtonCount="7" FirstPageText="«" LastPageText="»" />    
                   **<PagerTemplate>**     
                        <div style="float: left; margin-left: 12px;">    
                            <div style="float: left; margin: 4px 6px 0px 0px;">Page Size</div>    
                            <asp:DropDownList ID="ddlPageSizeChange" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PageSizeChange">    
                                <asp:ListItem>15</asp:ListItem>    
                                <asp:ListItem>25</asp:ListItem>    
                                <asp:ListItem>50</asp:ListItem>    
                                <asp:ListItem>100</asp:ListItem>    
                            </asp:DropDownList>    
                        </div>    
                        <div class="gridCount" runat="server" id="divGridCount"><b>1</b> Items Found  </div>    
                    </PagerTemplate>      
</asp:GridView>  

更新 1:

ページング 1 2 3 4 5 を表示できますが、問題は次のとおりです。Pag​​erSetting と PagerTemplate の両方を使用することはできません。グリッドビューに両方 (PagerSetting と PagerTemplate) がある場合、ページング (1 2 3 4 5) は表示されません。ページングが表示されているよりもPagerTemplateを削除すると(1 2 3 4 5 ...)意味がありますか?

アップデート:

ここに私が取得しようとしているものがあります:

<< < 1 2 3 4 5 ..... > >> 見つかった総ページ数 80 - ページ 1/80 - ページサイズ {15,25,50,10} (これはドロップダウン リストになります)

4

1 に答える 1

1

次のコードを使用してこれを行うことができます

  1. バックエンド コード (グリッドビューの行作成イベント):

    protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.Pager)
    {
        TableRow tr = (TableRow)e.Row.Cells[0].Controls[0].Controls[0];
        if (tr.Cells[1] != null && (((tr.Cells[1]).Controls[0]) is LinkButton))
        {
            LinkButton btnPrev = (LinkButton)(tr.Cells[1]).Controls[0];
            if (btnPrev.Text == "...")
            {
                (((tr.Cells[1]).Controls[0]) as LinkButton).Text = "<";
            }
        }
        if (tr.Cells[tr.Cells.Count - 2] != null && (((tr.Cells[tr.Cells.Count - 2]).Controls[0]) is LinkButton))
        {
            LinkButton btnNext = (LinkButton)(tr.Cells[tr.Cells.Count - 2]).Controls[0];
            if (btnNext.Text == "...")
            {
                (((tr.Cells[tr.Cells.Count - 2]).Controls[0]) as LinkButton).Text = ">";
            }
        }
    }
    

    }

  2. pagersetting を次のように使用します。

    <PagerSettings  Mode="NumericFirstLast" FirstPageText="<<"
    LastPageText=">>" />
    

出力が得られます。:)

注: グリッドのpageSizeAllowPaging ="true"を設定することを忘れないでください。

于 2015-09-25T13:20:13.823 に答える