473,289 Members | 1,875 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,289 software developers and data experts.

capturing checkbox.checked in repeater control

Hi,

I have a problem capturing the checkboxes that are checked, I get false
irrespective of wether they are checked or not.

I have gone thru the sample code on this forum, but they dun seem to work.
This is the code that I used to go thru the repeater control to find my
checkboxes.

foreach(RepeaterItem r in MyRepeater.Items)
{
for (int i=1; i<=6; i++) //6 checkboxes
{
CheckBox chk = (CheckBox)r.FindControl("chkbox"+ i);
if(chk.Checked)
{
tstdAnswer += "1";
}
else
tstdAnswer += "0";
}
}
lbl2.Text += " tstdAnswer is: " + tstdAnswer;

I used the step-by-step debugger, n everytime, the program will loop
straight to the false code, n give me a "000000" string each time.

I databind the checkbox in the html code as below, display of the info is
perfectly correct, so the error shouldn't be here. Below is a cut-down
version of my code:

<ASP:REPEATER id="MyRepeater" runat="server">
<ItemTemplate>
<asp:CheckBox id="chkbox1" runat="server" Checked="false" visible='<%#
DataBinder.Eval(Container.DataItem, "choiceA").ToString() != "" %>' >
</asp:CheckBox>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</ASP:REPEATER>

TIA.
Andrew.

Nov 19 '05 #1
2 6362
Are you binding this in the Page_Load ??

Be sure to use the Page.IsPostBack method in your pageload.
Otherwise, the Repeater will keep getting reset, and all your checkboxes
will be in there default value (unchecked)

So, if you code looks something like this:

void Page_Load(object Sender, Eventargs e)
{
BindMyGrid(); //or whatever code you use to populate your repeater
}

Change it too:

void Page_Load(object Sender, Eventargs e)
{
if(!Page.IsPostBack)
BindMyGrid(); //or whatever code you use to populate your repeater
}

HTH

"Andrew" <An****@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hi,

I have a problem capturing the checkboxes that are checked, I get false
irrespective of wether they are checked or not.

I have gone thru the sample code on this forum, but they dun seem to work.
This is the code that I used to go thru the repeater control to find my
checkboxes.

foreach(RepeaterItem r in MyRepeater.Items)
{
for (int i=1; i<=6; i++) //6 checkboxes
{
CheckBox chk = (CheckBox)r.FindControl("chkbox"+ i);
if(chk.Checked)
{
tstdAnswer += "1";
}
else
tstdAnswer += "0";
}
}
lbl2.Text += " tstdAnswer is: " + tstdAnswer;

I used the step-by-step debugger, n everytime, the program will loop
straight to the false code, n give me a "000000" string each time.

I databind the checkbox in the html code as below, display of the info is
perfectly correct, so the error shouldn't be here. Below is a cut-down
version of my code:

<ASP:REPEATER id="MyRepeater" runat="server">
<ItemTemplate>
<asp:CheckBox id="chkbox1" runat="server" Checked="false" visible='<%#
DataBinder.Eval(Container.DataItem, "choiceA").ToString() != "" %>' >
</asp:CheckBox>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</ASP:REPEATER>

TIA.
Andrew.

Nov 19 '05 #2
U are right I am. I load the ds in the page_load, from there I call a method
BindRepeater(), which will load the repeater with the ds.datatable.

I already have the: if(!Page.IsPostBack) in my page_load. When I run the
program, I used the debugger n i detect that after i click the Next button,
the program calls the BindRepeater() method again, which will explain why i
get checkbox.checked false values each time.

So what I did for testing sake was to take away the BindRepeater method n
just insert its code straight into the Page_load. I used the debugger n saw
that when it reaches:
foreach(RepeaterItem r in MyRepeater.Items)
it just skips past this loop n proceed on.
I wonder why, hmmmm ...

TIA.
Andrew.

---------------------------------------------------------------------------------
"Grant Merwitz" wrote:
Are you binding this in the Page_Load ??

Be sure to use the Page.IsPostBack method in your pageload.
Otherwise, the Repeater will keep getting reset, and all your checkboxes
will be in there default value (unchecked)

So, if you code looks something like this:

void Page_Load(object Sender, Eventargs e)
{
BindMyGrid(); //or whatever code you use to populate your repeater
}

Change it too:

void Page_Load(object Sender, Eventargs e)
{
if(!Page.IsPostBack)
BindMyGrid(); //or whatever code you use to populate your repeater
}

HTH

"Andrew" <An****@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hi,

I have a problem capturing the checkboxes that are checked, I get false
irrespective of wether they are checked or not.

I have gone thru the sample code on this forum, but they dun seem to work.
This is the code that I used to go thru the repeater control to find my
checkboxes.

foreach(RepeaterItem r in MyRepeater.Items)
{
for (int i=1; i<=6; i++) //6 checkboxes
{
CheckBox chk = (CheckBox)r.FindControl("chkbox"+ i);
if(chk.Checked)
{
tstdAnswer += "1";
}
else
tstdAnswer += "0";
}
}
lbl2.Text += " tstdAnswer is: " + tstdAnswer;

I used the step-by-step debugger, n everytime, the program will loop
straight to the false code, n give me a "000000" string each time.

I databind the checkbox in the html code as below, display of the info is
perfectly correct, so the error shouldn't be here. Below is a cut-down
version of my code:

<ASP:REPEATER id="MyRepeater" runat="server">
<ItemTemplate>
<asp:CheckBox id="chkbox1" runat="server" Checked="false" visible='<%#
DataBinder.Eval(Container.DataItem, "choiceA").ToString() != "" %>' >
</asp:CheckBox>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</ASP:REPEATER>

TIA.
Andrew.


Nov 19 '05 #3

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

Similar topics

2
by: Alan Silver | last post by:
Hello, I have a repeater with a list of products in it. Each item in the repeater has a checkbox, allowing the product to be selected. When a link button is clicked, I want to loop through the...
2
by: Ceema M via DotNetMonster.com | last post by:
Hello all, I have a nested repeater, which displays categories(parent repeater) and corresponding subcategories(child repeater). Both repeaters have checkboxes. When I check category checkbox...
8
by: Alan Silver | last post by:
Hello, I have a repeater that has code like this... <ItemTemplate> <asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> .... other stuff goes here </ItemTemplate> There is a button below...
2
by: RichardH | last post by:
Hi, I have x number of table rows that all should have a checkbox and a dropdownlist on each row. The checkbox could be checked and the dropdown should contain y number of values that are...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
5
by: c_shah | last post by:
using VB.net (2005) ASP.net 2.0 I have a repeater control with the item template, in the item template I have two checkboxes How to capture event When user checks the checkboxes? What event...
1
by: Doogie | last post by:
Why is this code not allowing me to add a checkbox to it? <asp:repeater ID="RptTrip" Runat="server" EnableViewState="false"> <ItemTemplate> <asp:Checkbox AutoPostBack="True" ID="cb"...
3
by: Mahathi | last post by:
Hi I have a small problem in maintaining the state of a check box. Please do me a favour by telling me the procedure how to do that. My requirement is that "I have to map some roles with...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.