checkBoxList in a web form

I

ime

Hi
I don't know how to create connection between checkBoxList and a table from
a database. When I run the application I want to see all the names from a
table in a checkBoxList, and to check some of them if I want.
Thx
 
K

Karl Seguin

Ime,
not sure what part you are having trouble with. Getting the data from the
database, binding it to the checkboxlist, or boht?

Sub Page_Load
If Not Page.IsPostBack Then
myCheckboxList.DataSource = GetData()
myCheckboxList.DataValueField = "SomeId"
myCheckboxList.DataTextField = "Name"
myCheckboxList.DataBind()
end if
end sub

Function GetData() as DataTable
dim connection as new SqlConnection("CONNECTION STRING")
dim command as new SqlCommand(connection, "SELECT SomeId, [Name] From
SomeTable")
dim da as new SqlDataAdapter(command)
try
dim dt as new DataTable
connection.Open()
da.Fill(dt)
return dt
finally
connection.Dipose()
command.Dispose()
da.Dispose()
end trt
end function

Might not compile but should give you the right idea.
Karl
 
I

ime

Thanks a lot

Karl Seguin said:
Ime,
not sure what part you are having trouble with. Getting the data from the
database, binding it to the checkboxlist, or boht?

Sub Page_Load
If Not Page.IsPostBack Then
myCheckboxList.DataSource = GetData()
myCheckboxList.DataValueField = "SomeId"
myCheckboxList.DataTextField = "Name"
myCheckboxList.DataBind()
end if
end sub

Function GetData() as DataTable
dim connection as new SqlConnection("CONNECTION STRING")
dim command as new SqlCommand(connection, "SELECT SomeId, [Name] From
SomeTable")
dim da as new SqlDataAdapter(command)
try
dim dt as new DataTable
connection.Open()
da.Fill(dt)
return dt
finally
connection.Dipose()
command.Dispose()
da.Dispose()
end trt
end function

Might not compile but should give you the right idea.
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


ime said:
Hi
I don't know how to create connection between checkBoxList and a table
from a database. When I run the application I want to see all the names
from a table in a checkBoxList, and to check some of them if I want.
Thx
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top