Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2006, 07:39 PM
Authorized User
 
Join Date: May 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default CheckBoxList and SqlDataSource

I am trying to find a way to access the multiple values of a CheckBoxList control.

Here is my code so far:
Code:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True">
            <asp:ListItem Value="02">Office 02</asp:ListItem>
            <asp:ListItem Value="12">Office 12</asp:ListItem>
        </asp:CheckBoxList></div>
        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
            DataTextField="Name" DataValueField="Zone">
        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ArchiveConnectionString %>"
            SelectCommand="SELECT * FROM [CheckBoxTest] WHERE (([Zone] = @Zone))">
            <SelectParameters>
                <asp:ControlParameter ControlID="CheckBoxList1" Name="Zone" PropertyName="SelectedValue"
                    Type="String" />

            </SelectParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>
I cannot find a way to access all the asp:listitems and do something like a SQL "in" statement. Second, I am not sure if it is even checking if the checkbox is checked.

Thanks
Extended

 
Old June 8th, 2006, 02:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

SelectedValue returns the first checked item in the list. So it will return something if found, but only the first one.

Brian
 
Old June 8th, 2006, 02:54 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Do you want to get each checkboxlist item and do something with them?
Try
        Dim li As New ListItem
        For Each li In CheckBoxList1.Items
           ... do something ...
        Next









Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckboxList and SQLDataSource keithroby ASP.NET 3.5 Basics 5 December 3rd, 2008 03:19 PM
Checkboxlist epkgupta Visual Studio 2005 0 March 11th, 2008 05:31 AM
checkboxlist problems hanoisky ASP.NET 2.0 Basics 1 December 6th, 2006 06:04 PM
CheckBoxList stu9820 ASP.NET 1.0 and 1.1 Basics 10 May 25th, 2006 08:15 PM
CheckBoxList eddiema VS.NET 2002/2003 1 April 9th, 2004 09:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.