1

以下のコードを書くと、グリッドビューにはコンテンツが表示されますが、シリアル番号 (SN) は 2 ページ目で再び 1 から始まります。

データは、カスタム コンポーネント (.DLL) を介して呼び出されます。

これを解決するには?

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  GridView1.PageIndex = e.NewPageIndex;
  DataTable dt = new DataTable();
  MMSLAYER.BLL.ReportBLL rb = new ReportBLL();
  dt = rb.atmservicing(Convert.ToInt32(ddlServiceBy.SelectedValue), 
  Convert.ToDateTime(txtDateFrom.Text), Convert.ToDateTime(txtDateTo.Text));
  GridView1.DataSource = dt;
  GridView1.DataBind();
  GridView1.Visible = true;
  ViewState["dtList"] = dt;
}
4

6 に答える 6

0

次の例のように、ソース ビューで、要素の AllowPaging 属性を true に設定します。

 <asp:GridView Runat="server" ID="GridView1" AllowPaging="true" />

ページのサイズを設定して、一度に表示される行数を指定できます。さらに、ナビゲーション ボタンの作成に使用するリンクのスタイルを設定できます。次のタイプから選択できます。

Next and previous buttons. The button captions can be any text you want.

Page numbers, which allow users to jump to a specific page. You can specify how many numbers are displayed; if there are more pages, an ellipsis (...) is displayed next to the numbers.

1 ページに表示される行数を変更するには

Select the GridView control, and in the Properties window, set PageSize to the number of rows you want to display per page.

[次へ] ボタンと [前へ] ボタンでデフォルトのページングを指定するには

Set the GridView control to allow paging.

In the Properties window, expand the PagerSettings node.

Set Mode to NextPrevious.
于 2013-10-25T05:14:24.953 に答える
0

GridView 宣言内に OnRowDataBound="GridView1_RowDataBound" を追加します。

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" ....>

GridView 内に TemplateField を追加します。

<asp:TemplateField HeaderText="Serial number">
    <ItemTemplate>
        <asp:Label ID="lblSerial" runat="server"></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

これを .cs ファイルに追加します

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblSerial = (Label)e.Row.FindControl("lblSerial");
            lblSerial.Text = ((GridView1.PageIndex * GridView1.PageSize) + e.Row.RowIndex + 1).ToString();
        }
    }
于 2013-10-26T12:15:29.477 に答える
0

次のコードを使用して印刷 (SN) しているように思えます。

<asp:Label ID="lblslno" Text='<%# Container.DisplayIndex + 1 %>' runat="server"/>

これの代わりに、次のコード行を試してください。

<asp:Label ID="lblslno" Text='<%# Container.DataItemIndex + 1 %>‘ runat="server"/>

DataItemIndexの代わりに を使用していることに注意してくださいDisplayIndex

于 2020-03-19T06:55:27.737 に答える