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 repeater and handle
each product whose checkbox is checked.
The repeater looks (greatly chopped down) like this...
<asp:Repeater ID="rptProducts " RunAt="Server">
<ItemTemplate >
<li><asp:CheckB ox ID="chkDelete" RunAt="server"/>
<%#DataBinder.E val(Container.D ataItem, "PName")%>
</ItemTemplate>
</asp:Repeater>
and the code for the link button looks like...
void lbtDeleteProduc ts_Click(object o, EventArgs e) {
for (int i=0; i<rptProducts.I tems.Count; i++) {
if (((CheckBox)rpt Products.Items[i].FindControl("c hkDelete")).Che cked) {
// do stuff here
}
}
}
The problem is that the loop works fine for the first product checked,
but not for any others. The weird thing is that this code is pretty much
identical to code I have used elsewhere that works fine. I can' see why
this only picks up the first checked checkbox. Anyone any idea why?
TIA
--
Alan Silver
(anything added below this line is nothing to do with me) 2 2080
I use the following code and have got it working all the time
foreach(Repeate rItem rptItem in ptProducts.Item s)
{
CheckBox chk = (CheckBox) rptItem.FindCon trol("chk_Selec t");
if(chk.Checked)
// do stuff here;
}
"Alan Silver" wrote: 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 repeater and handle each product whose checkbox is checked.
The repeater looks (greatly chopped down) like this...
<asp:Repeater ID="rptProducts " RunAt="Server"> <ItemTemplate > <li><asp:CheckB ox ID="chkDelete" RunAt="server"/> <%#DataBinder.E val(Container.D ataItem, "PName")%> </ItemTemplate> </asp:Repeater>
and the code for the link button looks like...
void lbtDeleteProduc ts_Click(object o, EventArgs e) { for (int i=0; i<rptProducts.I tems.Count; i++) { if (((CheckBox)rpt Products.Items[i].FindControl("c hkDelete")).Che cked) { // do stuff here } } }
The problem is that the loop works fine for the first product checked, but not for any others. The weird thing is that this code is pretty much identical to code I have used elsewhere that works fine. I can' see why this only picks up the first checked checkbox. Anyone any idea why?
TIA
-- Alan Silver (anything added below this line is nothing to do with me)
>I use the following code and have got it working all the time
Thanks, but that did the same as my code.
I have this sort of code working in plenty other places, I'm sure
there's some quirk here that I haven't noticed. I was hoping someone
else would spot it ;-( foreach(Repeat erItem rptItem in ptProducts.Item s) { CheckBox chk = (CheckBox) rptItem.FindCon trol("chk_Selec t"); if(chk.Checked) // do stuff here; }
"Alan Silver" wrote:
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 repeater and handle each product whose checkbox is checked.
The repeater looks (greatly chopped down) like this...
<asp:Repeater ID="rptProducts " RunAt="Server"> <ItemTemplate > <li><asp:CheckB ox ID="chkDelete" RunAt="server"/> <%#DataBinder.E val(Container.D ataItem, "PName")%> </ItemTemplate> </asp:Repeater>
and the code for the link button looks like...
void lbtDeleteProduc ts_Click(object o, EventArgs e) { for (int i=0; i<rptProducts.I tems.Count; i++) { if (((CheckBox)rpt Products.Items[i].FindControl("c hkDelete")).Che cked) { // do stuff here } } }
The problem is that the loop works fine for the first product checked, but not for any others. The weird thing is that this code is pretty much identical to code I have used elsewhere that works fine. I can' see why this only picks up the first checked checkbox. Anyone any idea why?
TIA
-- Alan Silver (anything added below this line is nothing to do with me)
--
Alan Silver
(anything added below this line is nothing to do with me) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: charliewest |
last post by:
Hello -
I'm using a Repeater control to render information in a very customized
grid-like table. The Repeater control is binded to a DataSet with several
records of information. Within the Repeater control, I've placed
DropDownLists and CheckBoxes.
When the user has updated the information, he/he clicks the submit button
which is outside the scope of the Repeater control.
|
by: Alan Silver |
last post by:
Hello,
I have a page in which I'm trying to give the user the chance to
manipulate a list of items. These are the price variations for a
product, so each item consists of a name (eg, small, medium, large), a
price, a checkbox to say whether or not the variation is on special
offer and a special price.
I can pull the values out of the database OK and display them in a
repeater. What I want to do is have a set of controls below the...
|
by: Andrew |
last post by:
Hi,
I am working on a questionnaire. I have displayed a questionnaire using a
repeater control. The itemtemplate is as below (quite cut down):
<ItemTemplate>
<tr><td>
<%# DataBinder.Eval(Container.DataItem, "question")%>
</td></tr>
<tr><td>
|
by: Andrew |
last post by:
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)
|
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 and subcategory check boxes and click on
submit button , I have to retrieve the corresponding categoryid and
subcategory id, so that I can store it to a table. I am getting the
categoryid but I am failing to get subcategoryid(actually I don't know...
| |
by: renil |
last post by:
I have a repeater control that displays info. from a datatable. Each row in
the repeater has a checkbox. Also, I have a delete linkbutton outside the
repeater control. What I'm trying to do when the delete linkbutton is
clicked is get the SubscriptionID from the repeater control for each row in
which the checkbox is checked, then call a delete function. (See the code
for the .aspx and .aspx.cs below.)
The problem I'm having is that I...
|
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 the repeater. When clicked, it is supposed to
|
by: Doogie |
last post by:
Hi, I have been trying to get a checkbox added to a repeater control
of mine and then try to access events of the repeater control when a
user clicks the checkbox. At first, since the control is tied to xsl,
I added the checkbox there. That works fine, but I cannot get any
information about the checkbox (i.e. checked, unchecked, etc) when I
pass data from the xsl over to a method in java. I can get info on
the other columns but not...
|
by: adiel_g |
last post by:
I am trying to loop through a repeater to retrieve a dataitem field
but am getting a NullReferenceException.
I can find a checkbox control but cannot find a dataitem field. Here
is the code that is looping through the repeater:
Dim rc As RepeaterItemCollection = rptReport.Items
Dim ri As RepeaterItem
Dim chkSelected As System.Web.UI.WebControls.CheckBox
Dim customer As String
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |