Determine Which Checkboxes are Checked

W

Wayne Wengert

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>
 
G

Guest

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...
 
W

Wayne Wengert

Kostas;
Exactly what I wanted. Thank you

Konstantinos Pantos said:
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 said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top