ASP.NET asp:GridView 行绑定事件
asp.net 我想要判断如果UserName=AAA,隐藏该行数据的最后一列,不允许用户操作
使用到行绑定事件
前台:
<asp:GridView ID="grvDictList" runat="server" GridLines="None" AutoGenerateColumns="False"
Width="100%" OnRowCommand="grvDictList_RowCommand" EmptyDataText="数据为空" OnRowDataBound="grvDicList_RowDataBound"
CssClass="table table-striped table-bordered table-hover shebtable text-center">
</asp:GridView>
后台:
protected void grvDicList_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView drv = (DataRowView)e.Row.DataItem; if (drv.Row["fUserName"].ToString() == "AAA") //如果有出现 { e.Row.Cells[7].CssClass = "hidden"; //隐藏该行第8列 //从0开始计数 } } }