• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 843
  • Last Modified:

checkbox list wth database

I have one table name having 2 fileds did(int) and dname(nvarchar(20)) and I want to use in CheckBoxList and I want to save it into another table as anyoen selected or not selected so how I will manage thses ids.
  • 4
  • 3
1 Solution
Senthil BCommented:
When you load the data into list box you have to load the ids into value property and the name should be visible. example for you.

<form action="">
<input type="radio" name="rs1" value="zero" checked>zero
<input type="radio" name="rs1" value="one">one
<input type="radio" name="rs1" value="two">two
<input type="checkbox" name="cb1" value="cb 1">cb 1
<input type="checkbox" name="cb2" value="cb 2">cb 2
<input type="checkbox" name="cb3" value="cb 3">cb 3
<input type="button" value="Show checked radio value" onclick="
<input type="button" value="Show all checked values" onclick="
<input type="reset">

<script type="text/javascript">

function showRadioChecked(rSet)
var i = rSet.length;
if (rSet[i].checked) return rSet[i].value;

function showAllChecked(f)
var el, els = f.elements;
var x = '';
var i = els.length;
el = els[i];
if (el.checked){
x += '\n' + el.type + ': ' + el.value;
return x;
I'll do it in parts. (example in vb.net, data coming from access)

1. Fill the checkboxList with the id and dname
    'Use a string variable to hold the ConnectionString.
    Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                "Data Source=C:\File Databases\NWIND.MDB"

    'Create an OleDbConnection object,
    'and then pass in the ConnectionString to the constructor.
    Dim cn As OleDbConnection = New OleDbConnection(connectString)

    'Open the connection.

    'Use a variable to hold the SQL statement.
    Dim selectString As String = "SELECT ID, dname FROM YourTable"

    'Create an OleDbCommand object.
    'Notice that this line passes in the SQL statement and the OleDbConnection object.
    Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn)

    'Send the CommandText to the connection, and then build an OleDbDataReader.
    'Note: The OleDbDataReader is forward-only.
    Dim reader As OleDbDataReader = cmd.ExecuteReader()

         CheckBoxList1.Items.Add(new ListItemreader("dname").ToString(), ListItemreader("ID").ToString())         
    End While

    'Close the reader and the related connection.

Open in new window

2. Retrieve all the values back

' Iterate through the Items collection of the CheckBoxList
         ' control and display the selected items.
         Dim i As Integer

         For i=0 To checkboxlist1.Items.Count - 1

            If checkboxlist1.Items(i).Selected Then

               Message.Text &= checkboxlist1.Items(i).Value & "<br />"

            End If


Open in new window

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

jyotiramanAuthor Commented:
no it is not what exact I want I am using SQl server 2005 and ASP.Net(c#)
jyotiramanAuthor Commented:
...... good .........
Did you get any progress with my comments ?
jyotiramanAuthor Commented:
If it's good, why only a B-grade ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now