简体   繁体   中英

How to set dynamically check boxes disable Property?

I added check boxes dynamically using data table and grid view. But all the check boxes are disable. How to enable it?

this is my code

    DataTable dt = new DataTable("UserAcess");         

    DataColumn dc1 = new DataColumn("PageName");
    dt.Columns.Add(dc1);


    foreach (var item in RoleName)
    {
        DataColumn dc = new DataColumn(item.RoleName, typeof(bool)); 
        dt.Columns.Add(dc);

    }



    foreach (var page in pageName)
    {

        DataRow dr = dt.NewRow();

        dr["PageName"] = page.PAGE_NAME;

         foreach (var role in RoleName)
        {                  

           dr[role.RoleName] = false; 

        }
        dt.Rows.Add(dr);
    }

    gridUserAcess.DataSource = dt;
    gridUserAcess.DataBind();

this is my grid view.

  <asp:GridView ID="gridUserAcess" runat="server">


    </asp:GridView>

I don't knowhow to set check box property. Please help me..

找到网格内的复选框,然后在找到复选框后使用.Enabled属性启用false。

这个?

 Page.FindControl("yourCheckBoxId").Enabled=true;    

what to you mean by "Dynamic" - are the checkboxes in the markup of your GridView or do you create them somewhere else in your code behind.

You can use Eval in your Markup:

<asp:CheckBox ID="deactivated" runat="server" checked="<%#Eval(Container.DataItem, 'Deactivated')%>"></asp:CheckBox>

Otherwise use

gridUserAccess.FindControl()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM