J
Justin Dyer
I have a DataGrid that has a checkbox and a bound column. When the user
clicks a button, I want to iterate through all the items in the datagrid and
display the text:
[value of databound column] is/is not checked. How do I do that? Thanks in
advance for your help.
Here is my aspx code:
<aspataGrid id="DataGrid1"
style="Z-INDEX: 101; LEFT: 176px; POSITION: absolute;
TOP: 112px"
runat="server"
AutoGenerateColumns="False"
EnableViewState="True">
<ItemStyle BackColor="Silver"></ItemStyle>
<HeaderStyle ForeColor="Transparent"
BackColor="SandyBrown"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Include?">
<ItemTemplate>
<asp:CheckBox id="IncludeItem"
EnableViewState="True"
Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ItemDesc"
HeaderText="Item Description">
</asp:BoundColumn>
</Columns>
</aspataGrid>
Here is my C# code:
foreach (DataGridItem dgiItem in DataGrid1.Items)
{
// Make sure this is an item and not a header or footer
if ((dgiItem.ItemType == ListItemType.Item) ||
(dgiItem.ItemType == ListItemType.AlternatingItem))
{
tc = dgiItem.Cells;
if (((CheckBox)(dgiItem.FindControl("IncludeItem"))).Checked)
{
lblResult.Text += "is checked.\n"; // I want "value of ItemDesc is
checked"
}
else
{
lblResult.Text += "is not checked.\n"; // I want "value of ItemDesc
is not checked"
}
}
}
clicks a button, I want to iterate through all the items in the datagrid and
display the text:
[value of databound column] is/is not checked. How do I do that? Thanks in
advance for your help.
Here is my aspx code:
<aspataGrid id="DataGrid1"
style="Z-INDEX: 101; LEFT: 176px; POSITION: absolute;
TOP: 112px"
runat="server"
AutoGenerateColumns="False"
EnableViewState="True">
<ItemStyle BackColor="Silver"></ItemStyle>
<HeaderStyle ForeColor="Transparent"
BackColor="SandyBrown"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Include?">
<ItemTemplate>
<asp:CheckBox id="IncludeItem"
EnableViewState="True"
Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ItemDesc"
HeaderText="Item Description">
</asp:BoundColumn>
</Columns>
</aspataGrid>
Here is my C# code:
foreach (DataGridItem dgiItem in DataGrid1.Items)
{
// Make sure this is an item and not a header or footer
if ((dgiItem.ItemType == ListItemType.Item) ||
(dgiItem.ItemType == ListItemType.AlternatingItem))
{
tc = dgiItem.Cells;
if (((CheckBox)(dgiItem.FindControl("IncludeItem"))).Checked)
{
lblResult.Text += "is checked.\n"; // I want "value of ItemDesc is
checked"
}
else
{
lblResult.Text += "is not checked.\n"; // I want "value of ItemDesc
is not checked"
}
}
}