473,387 Members | 1,698 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,387 software developers and data experts.

Determine Which Checkboxes are Checked

I have an aspx page which contains a datalist, which in turn, is populated
with checkboxes based on the contents of a SQL table (see code below). I
want a routine to go through all the checkboxes in this set and determine
which ones the user checked. I know I've seen some nice tight routines to do
this but I had no luck Googling for it.

================== Code ======================
<asp:DataList ID="DataList1" runat="server" DataKeyField="Interest"
RepeatColumns="4" DataSourceID="SqlDataSource1"

CellSpacing="2" SelectedIndex="0" Font-Bold="False" Font-Italic="False"

Font-Overline="False" Font-Strikeout="False" Font-Underline="False"

HorizontalAlign="Left" RepeatDirection="Horizontal" ShowFooter="False"

ShowHeader="False" Height="248px" Width="448px">
<ItemTemplate>

<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval("Interest") %>'
/>

</ItemTemplate>

</asp:DataList>
Feb 5 '06 #1
2 1404
A quick way to establish which DataList items are selected is by iterating
the DataList's Items Collection:
foreach (DataListItem item in DataList1.Items)
{
if (((CheckBox)item.FindControl("CheckBox1")) != null &&
((CheckBox)item.FindControl("CheckBox1")).Checked)
{
//Do what you want with this row
}
}
Hope this helps...

--
_________________________
Kostas Pantos [MCP]
http://kostas.pantos.name
"Wayne Wengert" wrote:
I have an aspx page which contains a datalist, which in turn, is populated
with checkboxes based on the contents of a SQL table (see code below). I
want a routine to go through all the checkboxes in this set and determine
which ones the user checked. I know I've seen some nice tight routines to do
this but I had no luck Googling for it.

================== Code ======================
<asp:DataList ID="DataList1" runat="server" DataKeyField="Interest"
RepeatColumns="4" DataSourceID="SqlDataSource1"

CellSpacing="2" SelectedIndex="0" Font-Bold="False" Font-Italic="False"

Font-Overline="False" Font-Strikeout="False" Font-Underline="False"

HorizontalAlign="Left" RepeatDirection="Horizontal" ShowFooter="False"

ShowHeader="False" Height="248px" Width="448px">
<ItemTemplate>

<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval("Interest") %>'
/>

</ItemTemplate>

</asp:DataList>

Feb 5 '06 #2
Kostas;
Exactly what I wanted. Thank you

"Konstantinos Pantos" <Ko****************@discussions.microsoft.com> wrote
in message news:D5**********************************@microsof t.com...
A quick way to establish which DataList items are selected is by iterating
the DataList's Items Collection:
foreach (DataListItem item in DataList1.Items)
{
if (((CheckBox)item.FindControl("CheckBox1")) != null &&
((CheckBox)item.FindControl("CheckBox1")).Checked)
{
//Do what you want with this row
}
}
Hope this helps...

--
_________________________
Kostas Pantos [MCP]
http://kostas.pantos.name
"Wayne Wengert" wrote:
I have an aspx page which contains a datalist, which in turn, is
populated
with checkboxes based on the contents of a SQL table (see code below). I
want a routine to go through all the checkboxes in this set and determine
which ones the user checked. I know I've seen some nice tight routines to
do
this but I had no luck Googling for it.

================== Code ======================
<asp:DataList ID="DataList1" runat="server" DataKeyField="Interest"
RepeatColumns="4" DataSourceID="SqlDataSource1"

CellSpacing="2" SelectedIndex="0" Font-Bold="False" Font-Italic="False"

Font-Overline="False" Font-Strikeout="False" Font-Underline="False"

HorizontalAlign="Left" RepeatDirection="Horizontal" ShowFooter="False"

ShowHeader="False" Height="248px" Width="448px">
<ItemTemplate>

<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval("Interest")
%>'
/>

</ItemTemplate>

</asp:DataList>

Feb 5 '06 #3

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

Similar topics

2
by: Pete | last post by:
There is a Summary/Example further down... On page one of my site I have a form with some checkboxes and detailed descriptions. When the form is submitted (to page two), the values of the...
8
by: Ralph Freshour | last post by:
I have multiple checkbox's created with an array name because I have many on the same web page - their names are like: frm_chk_delete frm_chk_delete frm_chk_delete frm_chk_delete etc. Here...
5
by: @(none) | last post by:
I have a page which is a set of CheckBoxes generated daily and thus the number of Checkboxes changes each day. What I want to do is allow the user to select one or more checkboxes and the push a...
4
by: david | last post by:
I have an array of CheckBoxes which dynamically display in a web form. How to detect and determine which CheckBox' check status changed? For example, Array(i, j) from checked to Unchecked and...
3
by: xianxian | last post by:
Hi guys, I'm having trouble getting my Datagrid to display according to Checkboxes checked values. On my Checkboxes, I have 5 values :- 1) Apartment/Condo 2) Executive Condo 3) Detached 4)...
6
by: jeffsnox | last post by:
Hi, I have multiple checkboxes on the same form as follows: <input type='checkbox' name='cbtype' value='1'> <input type='checkbox' name='cbtype' value='2'> <input type='checkbox'...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
5
by: pleaseexplaintome | last post by:
Hi I need to determine the most recent check box that was checked. Let's say I have 5 checkboxes. CB 1 is checked and I then check CB 5. How do I know CB 5 was just checked, regardless of the fact...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...
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...

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.