Solved

checkbox list wth database

Posted on 2010-09-08
8
835 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:jyotiraman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:senthilkumarsb
ID: 33634051
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="">
<div>
<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
<br>
<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
<br>
<input type="button" value="Show checked radio value" onclick="
alert(showRadioChecked(this.form.rs1));
"><br>
<input type="button" value="Show all checked values" onclick="
alert(showAllChecked(this.form));
"><br>
<input type="reset">
</div>
</form>

<script type="text/javascript">

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

function showAllChecked(f)
{
var el, els = f.elements;
var x = '';
var i = els.length;
while(i--){
el = els[i];
if (el.checked){
x += '\n' + el.type + ': ' + el.value;
}
}
return x;
}
</script>
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33634111
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.
    cn.Open()

    '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()

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

    'Close the reader and the related connection.
    reader.Close()
    cn.Close()

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33634116
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

         Next

Open in new window

0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:jyotiraman
ID: 33635012
no it is not what exact I want I am using SQl server 2005 and ASP.Net(c#)
0
 

Author Comment

by:jyotiraman
ID: 33660034
...... good .........
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33660040
Did you get any progress with my comments ?
0
 

Author Closing Comment

by:jyotiraman
ID: 33660069
good
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33660084
If it's good, why only a B-grade ?
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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