disable items in CheckBoxList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sql

    #1

    disable items in CheckBoxList

    Hi all,
    I am using a CheckBoxList control on my aspx page that I bind to an array
    at runtime. After I databind it, I check two of the items in the
    CheckBoxList controls. Now I also need to disable these two items so that
    users can't uncheck them. But I don't know how to disable individual items.
    Can you please help me achieving this(preferably at runtime)?

    Thanks in advance.


  • Jody Gelowitz

    #2
    Re: disable items in CheckBoxList

    I am sure that this can be improved upon, but here is something that works.
    To test the code out (listed below), simply add a CheckBoxList control to a
    web form (name = "clb") and add the code below to the Page_Load event. When
    you run the form, there will be 4 items which start out as unchecked. When
    you click on an item, it will become checked and you will not be able to
    uncheck it. This should give you a base to work from.

    HTH,
    Jody

    _______________ ___

    Dim x() As String = {1, 2, 3, 4}

    Dim intCount As Integer

    Dim strItemName As String

    Dim strScript As String

    clb.DataSource = x

    clb.DataBind()

    For intCount = 0 To x.Length - 1

    strItemName = clb.ClientID & "_" & intCount.ToStri ng

    strScript = "<script language = jscript for =" & strItemName & " event
    =""onclick"" >" & ControlChars.Cr Lf

    strScript &= strItemName & ".checked='true ';" & ControlChars.Cr Lf

    strScript &= " </script> " & ControlChars.Cr Lf

    RegisterClientS criptBlock("scr ipt" & intCount.ToStri ng, strScript)

    Next

    _______________ ____


    "sql" <donotspam@nosp aml.com> wrote in message
    news:ehLpFFeQFH A.2132@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Hi all,
    > I am using a CheckBoxList control on my aspx page that I bind to an
    > array at runtime. After I databind it, I check two of the items in the
    > CheckBoxList controls. Now I also need to disable these two items so that
    > users can't uncheck them. But I don't know how to disable individual
    > items. Can you please help me achieving this(preferably at runtime)?
    >
    > Thanks in advance.
    >[/color]


    Comment

    • sql

      #3
      Re: disable items in CheckBoxList

      Thanks.

      "Jody Gelowitz" <jgelowitz_nosp am@blah.leevall ey.com> wrote in message
      news:uqbl4qiQFH A.3120@TK2MSFTN GP10.phx.gbl...[color=blue]
      >I am sure that this can be improved upon, but here is something that works.
      >To test the code out (listed below), simply add a CheckBoxList control to a
      >web form (name = "clb") and add the code below to the Page_Load event.
      >When you run the form, there will be 4 items which start out as unchecked.
      >When you click on an item, it will become checked and you will not be able
      >to uncheck it. This should give you a base to work from.
      >
      > HTH,
      > Jody
      >
      > _______________ ___
      >
      > Dim x() As String = {1, 2, 3, 4}
      >
      > Dim intCount As Integer
      >
      > Dim strItemName As String
      >
      > Dim strScript As String
      >
      > clb.DataSource = x
      >
      > clb.DataBind()
      >
      > For intCount = 0 To x.Length - 1
      >
      > strItemName = clb.ClientID & "_" & intCount.ToStri ng
      >
      > strScript = "<script language = jscript for =" & strItemName & " event
      > =""onclick"" >" & ControlChars.Cr Lf
      >
      > strScript &= strItemName & ".checked='true ';" & ControlChars.Cr Lf
      >
      > strScript &= " </script> " & ControlChars.Cr Lf
      >
      > RegisterClientS criptBlock("scr ipt" & intCount.ToStri ng, strScript)
      >
      > Next
      >
      > _______________ ____
      >
      >
      > "sql" <donotspam@nosp aml.com> wrote in message
      > news:ehLpFFeQFH A.2132@TK2MSFTN GP09.phx.gbl...[color=green]
      >> Hi all,
      >> I am using a CheckBoxList control on my aspx page that I bind to an
      >> array at runtime. After I databind it, I check two of the items in the
      >> CheckBoxList controls. Now I also need to disable these two items so that
      >> users can't uncheck them. But I don't know how to disable individual
      >> items. Can you please help me achieving this(preferably at runtime)?
      >>
      >> Thanks in advance.
      >>[/color]
      >
      >[/color]


      Comment

      Working...