473,414 Members | 1,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

checkboxcontrol does not work

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>
Nov 19 '05 #1
1 846
Is the ViewState of the control/page maybe disabled?

--
Sonu Kapoor - [MCP]
ASP.NET Moderator
WebSite: http://www.Kapoorsolutions.com
Blog: http://www.Kapoorsolutions.com/blog/
ASP.NET News: http://www.Kapoorsolutions.com/reblogger/
"Jimmy" wrote:
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>

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.