disable items in CheckBoxList

Discussion in 'ASP .Net' started by sql, Apr 15, 2005.

  1. sql

    sql Guest

    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.
     
    sql, Apr 15, 2005
    #1
    1. Advertising

  2. 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.ToString

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

    strScript &= strItemName & ".checked='true';" & ControlChars.CrLf

    strScript &= " </script> " & ControlChars.CrLf

    RegisterClientScriptBlock("script" & intCount.ToString, strScript)

    Next

    ___________________


    "sql" <> wrote in message
    news:...
    > 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, Apr 16, 2005
    #2
    1. Advertising

  3. sql

    sql Guest

    Thanks.

    "Jody Gelowitz" <> wrote in message
    news:...
    >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.ToString
    >
    > strScript = "<script language = jscript for =" & strItemName & " event
    > =""onclick"">" & ControlChars.CrLf
    >
    > strScript &= strItemName & ".checked='true';" & ControlChars.CrLf
    >
    > strScript &= " </script> " & ControlChars.CrLf
    >
    > RegisterClientScriptBlock("script" & intCount.ToString, strScript)
    >
    > Next
    >
    > ___________________
    >
    >
    > "sql" <> wrote in message
    > news:...
    >> 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.
    >>

    >
    >
     
    sql, Apr 18, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hyrum Mortensen
    Replies:
    0
    Views:
    444
    Hyrum Mortensen
    Mar 4, 2004
  2. JD
    Replies:
    5
    Views:
    11,781
    NetArchitect
    Aug 8, 2007
  3. Patrick.O.Ige
    Replies:
    5
    Views:
    19,236
    Patrick.O.Ige
    Jun 19, 2005
  4. Bart Van Hemelen
    Replies:
    2
    Views:
    4,701
    Bart Van Hemelen
    Sep 4, 2006
  5. MattB
    Replies:
    1
    Views:
    1,528
    Page Brooks
    Apr 27, 2007
Loading...

Share This Page