473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

checkBoxList in a web form

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
Nov 19 '05 #1
2 1197
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" <ne***@zasto.com> wrote in message news:cu**********@bagan.srce.hr...
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

Nov 19 '05 #2
ime
Thanks a lot

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:um**************@tk2msftngp13.phx.gbl...
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" <ne***@zasto.com> wrote in message
news:cu**********@bagan.srce.hr...
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


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tom | last post by:
Hi, I have a webform which has DropDownList, RadioButtonList and CheckBoxList. All values are in webform, but not select from DB table as they do not need to be used as search requirements. ...
4
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something...
0
by: D. Shane Fowlkes | last post by:
OK - I'm looking for the best approach on how to do this. I have a form page where the user can edit their "Profile" (data) which is in SQL Server. It's your basic company information - address,...
0
by: D. Shane Fowlkes | last post by:
OK - I'm looking for the best approach on how to do this. I have a form page where the user can edit their "Profile" (data) which is in SQL Server. It's your basic company information - address,...
5
by: Eirik Eldorsen | last post by:
I'm trying to code a reapter that for each listelement show a checkboxlist. I'm almost there. The only thing I can't figure out is how to set the ID of the checkboxlists. This is my code:...
2
by: Simon Cheng | last post by:
Hi, For the following form: <form runat="server"> <asp:checkboxlist id="list" runat="server"> <asp:listitem runat="server" value="Cash" /> <asp:listitem runat="server" value="Check" />...
3
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the...
7
by: ThunderMusic | last post by:
Hi, I have a CheckBoxList and I want to add some javascript code to each CheckBox created by this CheckBoxList. I tried iterating through all items of the list, all the controls, do a FindControl,...
2
by: EnjoyLife | last post by:
I am new to ASP.NET and am trying to learn it the best that I can. I am trying to add some code in the If IntRowIndex > -1 statement to mark an item SELECTED before adding it to the CheckBoxList. ...
4
by: Marty | last post by:
I am using: VS2005 Pro WinXP Pro SP2 IIS 5.1 ..NET Framework 2.0.50727 I create a website using File>New>Web Site>ASP.NET. I put a ListBox, DropDownList, CheckBoxList and RadioButtonList on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.