checkBoxList in a web form

  • Thread starter Thread starter ime
  • Start date Start date
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
 
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
 
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
 
Back
Top