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

why won't this code work???

I have a datalist with a checkbox field.. when a button is pressed, I
want to output which checkboxes are selected.

<asp:datalist id="DataList1" runat="server">
<ItemTemplate>
<TABLE cellSpacing="0" cellPadding="0" border="0" width="100%">
<TR>
<TD>
<asp:CheckBox id="chkVehicleID" runat="server"></asp:CheckBox></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:datalist>

<asp:Button id="Button8" runat="server"></asp:Button>

Sub Button8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click

Dim dlItem As DataListItem

For Each dlItem In DataList1.Items

Response.Write(
CType(dlItem.FindControl("chkVehicleID"), CheckBox).Checked)
Next

End Sub

When I check a few boxes and press the button, I just get a list of
FALSE values... what's wrong here?!?

Thanks,
Peter
--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #1
2 992
For Each dlItem In DataList1.Items
chkVehicleID = dlItem.FindControl("chkVehicleID")
If chkVehicleID.Checked Then
'Get your selected values here
End If
Next
Hope that helps
Patrick
"Stimp" <re*@spumco.com> wrote in message
news:sl****************@carbon.redbrick.dcu.ie...
I have a datalist with a checkbox field.. when a button is pressed, I
want to output which checkboxes are selected.

<asp:datalist id="DataList1" runat="server">
<ItemTemplate>
<TABLE cellSpacing="0" cellPadding="0" border="0" width="100%">
<TR>
<TD>
<asp:CheckBox id="chkVehicleID" runat="server"></asp:CheckBox></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:datalist>

<asp:Button id="Button8" runat="server"></asp:Button>

Sub Button8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click

Dim dlItem As DataListItem

For Each dlItem In DataList1.Items

Response.Write(
CType(dlItem.FindControl("chkVehicleID"), CheckBox).Checked)
Next

End Sub

When I check a few boxes and press the button, I just get a list of
FALSE values... what's wrong here?!?

Thanks,
Peter
--

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #2
On Fri, 11 Nov 2005 Patrick.O.Ige <pa********@optusnet.com.au> wrote:
For Each dlItem In DataList1.Items
chkVehicleID = dlItem.FindControl("chkVehicleID")
If chkVehicleID.Checked Then
'Get your selected values here
End If
Next
Hope that helps
Patrick


cheers.. it turns out my original code was fine, but that I was
refreshing the datalist each time my page loaded

i.e. I hadn't placed a 'If Not IsPostBack' statement before the datalist
output.

so it was overwriting the state of my datalist. Doh!

--

"I hear ma train a comin'
.... hear freedom comin"

Nov 19 '05 #3

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

Similar topics

16
by: Kerry Neilson | last post by:
For the past couple of months, Idle won't start when I invoke it. I am at a complete loss for why this is. When this happens, they python command line still starts, and python works fine...
1
by: Jim | last post by:
Hey guys I DESPERATLY need some help with this small javascript i have on this website. All that it's supposed to do is change the button image once it's pressed but alas... I copy-pasted the code...
4
by: Mark | last post by:
the Following bit of code doesn't work. It seems to respond to the second, starting with 'add iif statement for Good Practice', but not to the first, starting 'add iif statement for archived' ...
5
by: John Warner | last post by:
I have a wierd problem that I can't find any reference to in the knowledge base. I develop simple databases at the company where I work, and many of them are used by hundreds of employees. We all...
7
by: simon | last post by:
I have simple html(aspx) page, but vertical height won't work. Even if i had set the height of a table=100%, the table is not 100% height. I spend a lot of time(my real page is more...
3
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from...
11
by: John Ortt | last post by:
Hi everyone. I have a database which I have developed in Access 2000 which is working nicely. The problem is that my customer only has Access 97. I tried to convert the database but the main...
7
by: Eran.Yasso | last post by:
Hi, I have project that automate excel(using Excel COM) which works fine in my home. I took the project from my home to work and tried to build the project but it won't built. I get error "The...
2
tpgames
by: tpgames | last post by:
Two days ago, MS office Word would type JP fonts, I thought. I didn't think I was using Works. Now, it won't type in JP. Jasc Paint shop pro 8, should type JP fonts because I am using XP, according...
4
by: z55177 | last post by:
My domain: http://www.esthevision.cz/ This is the cause of my problem. The template is supposed to look somewhat like this: PINK STRIPE http://themebot.com/website-templates/ht... I created an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.