簡體   English   中英

如何在頁腳gridview中添加信息總頁數和行數C#

[英]How add information total pages and rows in footer gridview c#

在頁腳gridview中添加有關總頁數和總行的信息時,我遇到問題,

這是我的HTML代碼;

<asp:GridView ID="GridView1" runat="server"
        onpageindexchanging="GridView1_PageIndexChanging" AllowPaging="True" 
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
        CellPadding="3" AutoGenerateColumns="False" Width="500px">

        <Columns>
            <asp:BoundField HeaderText="ProductId" DataField="ProductId" >
                 <ItemStyle Width="100px" />
                 </asp:BoundField>
            <asp:BoundField HeaderText="ProductName" DataField="ProductName">
                <ItemStyle Width="300px"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField HeaderText="SupplierId" DataField="SupplierId">
                <ItemStyle Width="100px"></ItemStyle>
            </asp:BoundField>
        </Columns>

        <PagerSettings FirstPageText="First" LastPageText="Last" PageButtonCount="7" Mode="NumericFirstLast" />
        <RowStyle ForeColor="#000066" />
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
    </asp:GridView>

這個aspx代碼:

public void BindData()
{
string strConnection = @"Data Source=.\sa;Initial Catalog=Northwind;Integrated Security=SSPI;";

        SqlConnection con = new SqlConnection(strConnection);
        con.Open();
        SqlCommand cmd = new SqlCommand("select ProductId, ProductName, SupplierId from Products", con);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        //Script row 10
        int rowcount = ds.Tables[0].Rows.Count;
        int remainingCount = 10 - (rowcount % 10);
        for (int i = 0; i < remainingCount; i++)
        {
            DataRow row = ds.Tables[0].NewRow();
            ds.Tables[0].Rows.Add(row);
        }
        //Script row ~10
        GridView1.DataSource = ds;
        GridView1.DataBind();
        con.Close();  

    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindData();  
    }

我的GridView

這是我的問題,我沒有找到添加信息的總頁數和行數的方法

任何人都可以改善我的代碼。

在綁定方法中調用它

int TotalRecord = ds.Rows.Count(); //This is total number of records in gridview
GridView1.DataSource = ds;
GridView1.DataBind();

您以后可以在標簽中調用Totalrecord或在Totalrecord中調用您想要的內容,也可以在這里引用: https : Totalrecord .count?view = netframework-4.8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM