By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,537 Members | 2,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,537 IT Pros & Developers. It's quick & easy.

Determine Which Checkboxes are Checked

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.