如何在gridview中添加一个显示总行数的附加单元格?

时间:2013-12-26 08:28:28

标签: c# asp.net gridview

我需要将总行数放在asp.net gridview底部的单元格中。我到目前为止可以在gridview之外显示它,但要求是在gridview本身的底部显示它。如何实现?

1 个答案:

答案 0 :(得分:0)

您需要将记录计数的变量定义为行号并定义标签以显示页脚的行数并参考下面的代码,它可能对您有所帮助。

private int RowNumber=0; // Define at the top
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {

      RowNumber += 1;
   }
    // you need to add one label at Footer section
   if (e.Row.RowType == DataControlRowType.Footer)
   {
      Label lblTotalRow = (Label)e.Row.FindControl("lblTotalRow");
      lblTotalRow.Text = RowNumber.ToString();
   }
}
相关问题