0
 protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {


            **if (e.Row.RowIndex >= gridview1.PageSize) // ROW FOOTER TOTAL**
            {

                e.Row.BackColor = System.Drawing.Color.Firebrick;
                e.Row.ForeColor = System.Drawing.Color.White;

            }
        }

此代码有时有效,有人可以帮助我

DM,干杯

4

4 回答 4

2

您可以尝试在 PreRender 事件中找到最后一列

protected void grid_PreRender(object sender, EventArgs e)
{
    GridViewRow row = grdAlert.Rows[grdAlert.Rows.Count - 1];

    // do stuff with your row
}

如果您只需要更改页脚的样式,您可以使用

<asp:GridView ID="grid" runat="server" FooterStyle="your style"></asp:GridView>
于 2013-09-13T09:34:55.917 回答
1

在完成绑定每一行之前,网格视图似乎没有行数。所以,另一个想法:

您能否确定 gridview 绑定到的数据表中的行数,然后将其存储在变量中以供以后使用?

你可以像这样找到最后一行

GridViewRow row = GridView1.Rows[GridView1.Rows.Count-1];

或使用这个

protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow) 
    {
        GridView grid = (GridView)sender;

        if(e.Row.RowIndex == (grid.Rows.Count - 1))
         {
             //last row
         }
    }
}
于 2013-09-13T09:17:26.863 回答
0

在您的页面加载方法中设置颜色如下

protected void Page_Load(object sender, EventArgs e)
{

    //code what you currently have ....
    // add below code after that
    GridViewRow row  = GridView1.Rows.Count-1;
    row.BackColor = System.Drawing.Color.Firebrick;
    row.ForeColor = System.Drawing.Color.White;
}
于 2013-09-13T09:32:37.580 回答
0

RowDataBound自从您发表评论以来,您似乎想检测页脚行//ROW FOOTER TOTAL,您只需要检查DataControlRowType.Footer

protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Footer)
    {
        // here it is
    }
}

否则,您可以将RowIndex与 undrlying 的行进行比较DataItem

DataRowView row = (DataRowView)e.Row.DataItem;
if (e.Row.RowIndex == row.DataView.Count - 1) ; // last row
于 2013-09-13T09:31:09.043 回答