arogmazorse
New Member
Is it possible to disable listitems in a checkbox list? For example, I would like to grey-out certain options from time to time.<BR><BR>thanks<BR><BR>masmithYou have your checkboxlist setup like:<BR><BR><asp:checkboxlist runat="server" id="chklist"><BR> <asp:listitem ... /><BR> ...<BR></asp:checkboxlist><BR><BR>I assume. Now, in your server-side code you can access each listitem in the checkboxlist similar to:<BR><BR>chklist<BR><BR>(I think - I don't have the docs in front of me, but I know you can reference individual listitems in a checkboxlist... either the above, or using Items(i) or something like that (I am using C# code up there, BTW). Consult the docs for the specifics.)<BR><BR>In any case, assume you can reference a checkboxlist's ith listitem by:<BR><BR>chklist<BR><BR>to disable it you can do:<BR><BR>chklist.Enabled = false;<BR><BR>hth (Again, my syntax may be a bit off; refer to the docs for precise syntax.)I have my checkboxlist set up like this:<BR><asp:CheckBoxList ID="chbxList" Runat=server></asp:CheckBoxList><BR><BR>and I'm trying to add the listitems in the server side code like this:<BR><BR>For i = lngOrigNbrLyrs To 1 Step -1<BR> If TypeName(g_lysMain.Item(i)) = "FeatureLayer" Then<BR> NewListItem = New ListItem()<BR> NewListItem.Text = g_lysMain.Item(i).Name<BR> If (map.WithinScaleRange(g_mapMain, g_lysMain.Item(i))) Then<BR> If (g_lysMain.Item(i).Visible) Then<BR> NewListItem.Selected = True ' Added a checked check-box<BR> End If<BR> Else ' Otherwise I'd like to disable the checkbox here<BR> NewListItem.Selected = False<BR> ' Disable some how?<BR> End If<BR> chbxList.Items.Add(NewListItem) <BR> End If<BR>Next<BR><BR>This loop works great - it puts all the listitems in, and checks the appropriate boxes - but I need to disable checkboxes. <BR>I tried to reference the listitem how you suggested but It raises an error saying that it cannot be indexed b/c it has no default property?<BR>Any suggestions. Thanks<BR><BR>masmith<BR>you still need to set the enabled property to false. If NewListItem doesn't have the property then chbxList.Items(n) should have itI agree, it seems like it should, but "Enable" is not a member of ListItems (which is what you end up accessing when you write chbxList.Items(n).Enable), and checkboxlist.enable just enables or disables the entire list, not individual elements.Just checked the docs, looks like you're right. Think you may be SOL. The solution here would be to write your own Web control that inherits (and hence extends) the CheckBoxList class...