Anyone know why the code below does not work. All I want is to check a
checkbox, then hit a button, then for the value of the DataKeyField in
the DataGrid to show up as the Text property in a Label. The DataGrid is
working OK as if the foreach loop, the bit where its coming unstuck is
the check box definition or test to see if it is checked. I don't get a
compilation error - just that it doesn't work.
<asp:DataGrid id="DataGrid1" DataKeyField="R equestID" runat="server"
Font-Size="X-Small">
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:CheckBox ID="checkboxSel ect"
Runat="server"> </asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
private void Button1_Click(o bject sender, System.EventArg s e)
{
StringBuilder sb = new StringBuilder() ;
foreach(DataGri dItem DGridItem in DataGrid1.Items )
{
CheckBox myCheckbox =
(CheckBox)DGrid Item.FindContro l("checkboxSele ct");
if(myCheckbox.C hecked == true)
{
sb.Append(DataG rid1.DataKeys[DGridItem.ItemI ndex].ToString());
}
}
Label.Text = sb.ToString();
}
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!