You must Sign In to post a response.
  • Category: ASP.NET

    How to check items in checkbox list ?

    Are you looking for a way to check items in checkbox list ? then read this thread to know how to check it


    I am having a CheckBoxList which is databound with a sql data source control and runtime it is fetching data from the database and displaying it.

    Now, from another table, I am having several data which I am fetching at code behind of the same page using code and wanting to match these data with the already binded data of the CheckListBox and if there will be any match, then that particular matched data/item will be selected on the CheckListBox.

    The code is as follows:-

    Dim old_desired_expertise As String = ds.Tables(0).Rows(0)(5).ToString
    Dim words As String() = old_desired_expertise.Split(New Char() {","c})
    Dim word As String
    For Each word In words

    For Each li As ListItem In chkboxlist_desired_expertise.Items
    If li.Text = word Then

    li.Selected = True

    End If



    But the abovde code is not working al all.

    Please Note: In the "ds.Tables(0).Rows(0)(5).ToString", I am having a string of comma separated values which is stored in the database.

    I am looking the help for the same, from you.
  • #763450
    Where are you calling this method?.

    If you are binding the data source in the page load you have to check the isPostback.

    By Nathan
    Direction is important than speed

  • #763465
    you can loop on checkbox list and check of item is match with your string
    see below snippet

    dim szArr as string() = old_desired_expertise.Split(",")

    dim szItem as string

    For Each szItem in szArr
    For Each li As ListItem In CheckBoxList1.Items
    If li.Value.toUpper() = szItem.toUpper() Then
    li.Selected = True
    End If

    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

Sign In to post your comments