checkboxcontrol does not work

J

Jimmy

Hi,

If i check my checkbox then it never returns true in the code below:
code:
private void Page_Load(object sender, System.EventArgs e)

{
// Put user code to initialize the page here

string[] ar = new string[]{"jack","jill"};
DataList1.DataSource=ar;
DataList1.DataBind();
}

private void Button2_Click(object sender, System.EventArgs e)
{

int i=0;
foreach(DataListItem item in DataList1.Items )
{
i+=1;
if (((CheckBox)item.FindControl("ChkBox1")).Checked)
{
//never comes here even if you check chkbox!!!
Label1.Text+="row " + i.ToString() + " is checked" +"<br>";
}
else
{
Label1.Text+="row " + i.ToString() + " is NOT checked"+"<br>";
}

}

}

page:
<asp:label id="Label1" style="Z-INDEX: 102; LEFT: 64px; POSITION: absolute;
TOP: 208px" runat="server"
Height="32px" Width="224px">Label</asp:label><asp:datalist
id="DataList1" style="Z-INDEX:

103; LEFT: 72px; POSITION: absolute; TOP: 8px" runat="server"
Height="200px" Width="360px">
<ItemTemplate>
<asp:CheckBox id="ChkBox1" runat="server"></asp:CheckBox>
<asp:Label text='<%# Container.DataItem %>' Runat=server>
</asp:Label>
</ItemTemplate>
</asp:datalist>
<asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 320px; POSITION:
absolute; TOP: 208px"

runat="server"
Text="Button"></asp:Button>
 

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,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top