Solved

How to get checkboxlist value from database

Posted on 2011-03-11
1
322 Views
Last Modified: 2012-05-11
I am saving value of checkbox list into database by 26,27 but I want when I visit that form checkbox with that value already checked.

Inshort I want to get checkboxlist value from database.

Can anyone please tell me how to do taht.
0
Comment
Question by:itgirl7
1 Comment
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35113327
Hi,

I am going to assume that you CheckBoxList is bounded to a datatable named dt, that have 2 columns, Name and Status, os the code below will loop the datasource and assign the check mark to according to the value of Status


CheckBoxList1.DataSource = dt
        CheckBoxList1.DataTextField = "Name"
        CheckBoxList1.DataBind()

        For Each dr In dt.Rows

            Dim checkItem As ListItem
            checkItem = CheckBoxList1.Items.FindByText(dr("Name").ToString)
            If checkItem IsNot Nothing Then
                If dr("Status") = 1 Then
                    checkItem.Selected = True
                End If
            End If

        Next

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now