473,714 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: Checkbox in datalist - checked status = ALWAYS FALSE!

Simple: I have a datalist that is holding a bunch of job opportunities.
Beside each opp (in the item template) there's a checkbox that says "apply".

After the datalist there's a button that say's "process". I want to LOOP
through each datalist entry and see if the user checked the check box.
Simple.

I wrote the code, but the checked value is ALWAYS False. Any ideas?

Here's the code...
Dim i As Integer, cb As CheckBox, MyJobId As Label, MyJob As Label,
JobAppliedFor As String
For i = 0 To Me.DataList1.It ems.Count - 1
cb = CType(Me.DataLi st1.Items(i).Co ntrols(7), CheckBox)
If cb.Checked = True Then ' THIS ALWAYS SAYS FALSE!!!
' get the job id and the job title
MyJobId = CType(Me.DataLi st1.Items(i).Co ntrols(1), Label)
MyJob = CType(Me.DataLi st1.Items(i).Co ntrols(3), Label)

' build a string of everything they checked
JobAppliedFor += MyJobId.Text & ":" & MyJob.Text & ","
End If
Next
Response.Write( JobAppliedFor)

Thanks in advance!
Nov 19 '05 #1
1 3777
Hi ???

Here's my solution to that one. Your problem is that you're looking for the
wrong thing in the wrong place! You need to find a control inside the
label, believe it or not.

It helps to set trace="true" and look through the hierarchy of the page.

Check out the code below and let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<form id="Form1" method="post" runat="server">
<asp:datalist id="DataList1" runat="server">
<itemtemplate >
<asp:label id="lblMyJobId " runat="server">
<%# DataBinder.Eval ( Container.DataI tem, "MyJobId")
%>
</asp:label>
<asp:label id="lblMyJob" runat="server">
<%# DataBinder.Eval ( Container.DataI tem, "MyJob") %>
</asp:label>
<asp:label id="Label3" runat="server">
<%# DataBinder.Eval (Container.Data Item,
"CurrencyValue" ) %>
</asp:label>
<asp:CheckBox id="thecheckbox " runat="server"
Checked='<%# DataBinder.Eval (Container.Data Item, "Boolean") %>'>
</asp:checkbox>
</itemtemplate>
</asp:datalist>
<p>
<asp:button id="Button1" runat="server"
Text="Button"></asp:button></p>
</form>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataList1.DataS ource = CreateDataSourc e()
DataList1.DataB ind()
End If
End Sub
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
Dim i As Integer, cb As CheckBox, _
MyJobId As DataBoundLitera lControl, _
MyJob As DataBoundLitera lControl, _
JobAppliedFor As String
For i = 0 To Me.DataList1.It ems.Count - 1
cb = DataList1.Items (i).FindControl ("thecheckbo x")
If Not IsNothing(cb) Then
If cb.Checked = True Then
MyJobId = DataList1.Items (i). _
FindControl("lb lMyJobID").Cont rols(0)
MyJob = DataList1.Items (i). _
FindControl("lb lMyJob").Contro ls(0)
JobAppliedFor = JobAppliedFor & MyJobId.Text & ":" & _
MyJob.Text & ","
End If
End If
Next
Response.Write( JobAppliedFor)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("MyJobId", GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("MyJob", GetType(String) ))
dt.Columns.Add( New DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Job " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

"VB Programmer" <xD**********@D ont.com> wrote in message
news:u3******** ******@tk2msftn gp13.phx.gbl...
Simple: I have a datalist that is holding a bunch of job opportunities.
Beside each opp (in the item template) there's a checkbox that says
"apply".

After the datalist there's a button that say's "process". I want to LOOP
through each datalist entry and see if the user checked the check box.
Simple.

I wrote the code, but the checked value is ALWAYS False. Any ideas?

Here's the code...
Dim i As Integer, cb As CheckBox, MyJobId As Label, MyJob As Label,
JobAppliedFor As String
For i = 0 To Me.DataList1.It ems.Count - 1
cb = CType(Me.DataLi st1.Items(i).Co ntrols(7), CheckBox)
If cb.Checked = True Then ' THIS ALWAYS SAYS FALSE!!!
' get the job id and the job title
MyJobId = CType(Me.DataLi st1.Items(i).Co ntrols(1), Label)
MyJob = CType(Me.DataLi st1.Items(i).Co ntrols(3), Label)

' build a string of everything they checked
JobAppliedFor += MyJobId.Text & ":" & MyJob.Text & ","
End If
Next
Response.Write( JobAppliedFor)

Thanks in advance!


Nov 19 '05 #2

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

Similar topics

3
2456
by: Adam Toline | last post by:
In reference to the following: http://www.bellecose.com/form.htm At the top of each column there is a box for "All". When one is checked I need to check all of (and only) those boxes underneath. Now, the rub here is that every checkbox on the page (except the "All"s)
3
1514
by: Amy Snyder | last post by:
For what I thought would be a very simple task is turning out to be very frustrating. I have been trying for a day now to extract checkbox values from my form and nothing is working. On my form load I am setting the values of my checkboxes: chk1.Attributes.Add("checkValue", "151010") chk2.Attributes.Add("checkValue", "151020") chk3.Attributes.Add("checkValue", "151030") chk4.Attributes.Add("checkValue", "151040")...
1
1353
by: Vannela | last post by:
I want to get the status of the checkbox control in the item template of the DataList in the code behind Using findcontrol i am not able to get the status of the checkbox . How shouls i get the status of the checkbox whether it is checked or not?\ Thank you
0
1285
by: yurps | last post by:
Hello I have a DataList like this <asp:DataList id="Questions" Runat="server"> <ItemTemplate> <table border="1"> <tr> <td> <asp:CheckBox ID="Yes" Runat="server"></asp:CheckBox> <input type="hidden" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "I_QUESTION_ID") %>' ></input>
0
1992
by: Faybert | last post by:
Hello, and Thanks in advance for any light you might shed on my troubles. I'm trying to setup a series of checkboxes, or a checkboxlist to control the results that are shown on a gridview control. I have a column in my database that hold the current status of the items in there. If I used a checkboxlist and populate it with my options, and set the SQL statement on my gridview control to: "SELECT , , , FROM WHERE
1
2170
by: rn5a | last post by:
A ASPX page has a DataList control with a few Labels. This page also has a CheckBox which resides OUTSIDE the DataList. By default, this CheckBox is checked. If the CheckBox is checked, then the Labels existing in the DataList should be visible but if the CheckBox is unchecked by the user, the Labels inside the DataList should be made invisible. How do I do this? Note that the AutoPostBack property of the CheckBox has been set to
0
1172
by: simonakiki | last post by:
i have checkbox in datalist and i need to find which checkbox is checked name of checkbox = CheckBox1 and name of datalist is DataList1 i am writng this code to find the checked checkbox foreach (DataListItem dli in DataList1.Items) { bool ok = ((CheckBox)dli.FindControl("CheckBox1")).Checked;
5
5812
by: simonakiki | last post by:
i have checkbox in datalist and i need to find which checkbox is checked name of checkbox = CheckBox1 and name of datalist is DataList1 i am writng this code to find the checked checkbox foreach (DataListItem dli in DataList1.Items) { bool ok = ((CheckBox)dli.FindControl("CheckBox1")).Checked;
4
1165
by: simonakiki | last post by:
i have checkbox in datalist and i need to find which checkbox is checked name of checkbox = CheckBox1 and name of datalist is DataList1 i am writng this code to find the checked checkbox foreach (DataListItem dli in DataList1.Items) { bool ok = ((CheckBox)dli.FindControl("CheckBox1")).Checked;
0
9319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9187
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9034
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7961
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6639
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4468
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4731
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3164
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.