473,325 Members | 2,342 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,325 software developers and data experts.

CheckBoxList check all

2
I'm not sure if this should be posted in the VB forum, the .NET forum or here. I know how to create a CheckBoxList, add items and have them checked or unchecked but my problem is I'm pulling the items from a database and don't know how to have them automatically checked. Can someone help with this? Thanks.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3. </script>
  4. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  5.     <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name" AutoPostBack="True"></asp:CheckBoxList>
  6.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Name] FROM [tblName]"></asp:SqlDataSource>
  7. </asp:Content>
  8.  
Aug 9 '07 #1
1 4859
prk72
2
Here is the answer:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub CheckBoxList1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         For Each item As ListItem In CheckBoxList1.Items
  5.             item.Selected = True
  6.         Next item
  7.     End Sub
  8. </script>
  9. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  10.     <asp:CheckBoxList ID="CheckBoxList1" runat="server"  AutoPostBack="true" DataSourceID="SqlDataSource1" 
  11.                                                                              DataTextField="Name" 
  12.                                                                              DataValueField="Name" 
  13.                                                                              OnDataBound="CheckBoxList1_DataBound" />
  14.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Name] FROM [tblName]"></asp:SqlDataSource>
  15. </asp:Content>
  16.  
Aug 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

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,...
3
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside Repeater_ItemBound - including setting checked/unchecked)....
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: Dune | last post by:
Hi, Is there anyway to get the datavaluefield from a databound checkboxlist using javascript? If not, is there any way to associate a custom attribute with the databound checkboxlist items so...
0
by: Nam | last post by:
I want to use the same sqlDataSource for two CheckBoxList controls in ASP.NET 2.0. For simplicity, I am using the case of only two CheckBoxList controls in the following example: My...
0
by: jeremy | last post by:
Had a tough time figuring this one out and couldn't find a good solution, so I thought I would post this and hopefully it will help someone out. When using DataBind to dynamically bind a list to...
6
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
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...
1
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.