我在 Gridview 中有一个 ItemTemplate 标签,我没有与任何 DataField 绑定。我将 userId 作为 GridView 的列之一。根据 userId 列,我想获取用户获得的资产总数。数据库中不存在 totalNo。我必须手动触发查询并获得总行数。
现在,如何将每个用户的这个 rowCount 放在 GridView 中?
有任何想法吗?我已经尝试过 onRowDataBound 和 FindControl,但我如何为该特定用户获取 rowIndex?
您在 GridView 上为 DataBound 添加一个事件函数,当它呈现 Header 时,您可以像这样更改它:
protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = "Custom header";
}
}
}