0

如何根据通过数据绑定加载的数据启用/禁用列表窗口上的删除按钮?我试图通过 GridView1_DataBound 事件访问数据,但是当我在 GridView1.Rows 中看到正确的行数时,内容似乎是空的。

protected void GridView1_DataBound(object sender, EventArgs e)
{
    foreach (GridViewRow row in GridView1.Rows)
    {
        //
        // Don't display delete link for non-admin users. (This is working fine.)
        //
        ((LinkButton)row.FindControl("DeleteLinkButton")).Visible = (DataAccess.GetUserInfo(true).UserType == DataAccess.UserType.Admin);

        //
        // TODO: Instead of just making the button visible, if it is visible, enable 
        // or disable based on the row's DATESTAMP column.
        //
        DateTime dateStamp = Convert.ToDateTime(row.Cells[11].Text); // NO DATA RETURNED??

    }
}
4

1 回答 1

0

改为尝试RowDataBound事件。每一行都会发生这种情况,因此您不必遍历网格行。但是,您必须在使用前检查行类型。为此,您将获得GridViewRowEventArgs. 这个MSDN 链接有示例代码。

于 2012-09-16T18:22:59.133 回答