1. 程式人生 > 其它 >ASP.NET asp:GridView 行繫結事件

ASP.NET asp:GridView 行繫結事件

asp.net 我想要判斷如果有資料fUserName=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";  //下標從0開始 隱藏第8列
               }
          }
 }