473,804 Members | 3,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to/Help: Getting Values for Selected Rows in a Repeater

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 cannot get the SubscriptionID for each row
in the repeater in which the checkbox is checked.

How can I cycle through each row in the repeater, check whether the checkbox
is checked or not, and, if it's checked, get the SubscriptionID for that row
in the repeater and send it to a delete function?

..aspx
<asp:Image ID="ImageDelete " runat="server"
ImageUrl="~/Images/16del.gif" ToolTip="Delete " ImageAlign="Mid dle" />
<asp:LinkButt on ID="LinkButtonD elete" runat="server"
OnClick="LinkBu ttonDelete_Clic k" ToolTip="Delete ">Delete</asp:LinkButton>
<br />
<asp:Repeater ID="RepeaterSch edules" runat="server"
OnItemCommand=" RepeaterSchedul es_ItemCommand" >
<HeaderTemplate >
<table>
<tr class="headerro w">
<td align="center" valign="middle" >
<asp:CheckBox
ID="CheckBoxSel ectedHeader" runat="server" AutoPostBack="T rue"
OnCheckedChange d="CheckBoxSele ctedHeader_Chec kedChanged" />
</td>
<td align="center" valign="middle" ></td>
<td align="center"
valign="middle" >Report</td>
<td align="center" valign="middle" >Path</td>
<td align="center"
valign="middle" >Description</td>
<td align="center" valign="middle" >Last
Executed</td>
<td align="center"
valign="middle" >Status</td>
<td align="center"
valign="middle" >Owner</td>
<td align="center" valign="middle" >Modified
By</td>
<td align="center" valign="middle" >Modified
Date</td>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<asp:CheckBox ID="CheckBoxSel ected"
runat="server" />
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<asp:LinkButt on ID="LinkButtonE dit"
runat="server" CommandArgument ='<%# DataBinder.Eval (Container.Data Item,
"SubscriptionID ")%>'>Edit</asp:LinkButton>
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"Report") %>
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"Path") %>
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"Description")% >
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"LastExecut ed") %>
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"Status") %>
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"Owner")%>
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"ModifiedBy ")%>
</td>
<td align="center" valign="middle"
style="backgrou nd-color: #EEEEEE">
<%# DataBinder.Eval (Container.Data Item,
"ModifiedDate") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:Repeater>
..aspx.cs
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
BuildSchedulesL ist();
}
}

private void BuildSchedulesL ist()
{
System.Data.Dat aTable tbl = new System.Data.Dat aTable("Schedul es");
System.Data.Dat aColumn colSubscription ID =
tbl.Columns.Add ("SubscriptionI D", typeof(string)) ;
System.Data.Dat aColumn colReport = tbl.Columns.Add ("Report",
typeof(string)) ;
System.Data.Dat aColumn colPath = tbl.Columns.Add ("Path",
typeof(string)) ;
System.Data.Dat aColumn colDescription =
tbl.Columns.Add ("Descriptio n", typeof(string)) ;
System.Data.Dat aColumn colLastExecuted =
tbl.Columns.Add ("LastExecuted" , typeof(System.D ateTime));
System.Data.Dat aColumn colStatus = tbl.Columns.Add ("Status",
typeof(string)) ;
System.Data.Dat aColumn colOwner = tbl.Columns.Add ("Owner",
typeof(string)) ;
System.Data.Dat aColumn colModifiedBy = tbl.Columns.Add ("ModifiedBy ",
typeof(string)) ;
System.Data.Dat aColumn colModifiedDate =
tbl.Columns.Add ("ModifiedDate" , typeof(System.D ateTime));

foreach (object in collection)
{
System.Data.Dat aRow row = tbl.NewRow();

row["SubscriptionID "] = subscription.Su bscriptionID;
row["Report"] = subscription.Re port;
row["Path"] = subscription.Pa th;
row["Descriptio n"] = subscription.De scription;
row["LastExecut ed"] = subscription.La stExecuted;
row["Status"] = subscription.St atus;
row["Owner"] = subscription.Ow ner;
row["ModifiedBy "] = subscription.Mo difiedBy;
row["ModifiedDa te"] = subscription.Mo difiedDate;

tbl.Rows.Add(ro w);
}
}

this.RepeaterSc hedules.DataSou rce = tbl;
this.RepeaterSc hedules.DataBin d();
}

protected void RepeaterSchedul es_ItemCommand( object source,
RepeaterCommand EventArgs e)
{
// Get the SubscriptionID
Response.Write( e.CommandArgume nt.ToString());
}

protected void LinkButtonDelet e_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.RepeaterSc hedules.Items.C ount; i++)
{
System.Web.UI.W ebControls.Chec kBox cb =
(System.Web.UI. WebControls.Che ckBox)this.Repe aterSchedules.I tems[i].FindCont
rol("CheckBoxSe lected");

if (cb.Checked)
{
// How can I get the SubscriptionID for each row with the
checkbox checked?
// Pass the SubscriptionID to the delete method
}
}
}


Jan 30 '06 #1
3 7843
foreach (RepeaterItem dataItem in RepeaterSchedul es.Items)
{
CheckBox ckDelete =
(CheckBox)dataI tem.FindControl ("CheckBoxSelec ted");
//txtSubscription ID is a <asp:Textbox/> that has
visible=false.
TextBox txtSubscription ID =
(TextBox)dataIt em.FindControl( "txtSubcription ID");
if (ckDelete.Check ed)
{
//delete the item
DoDelete(txtSub criptionID.Text );
}
}

HTH,
Chris

Jan 30 '06 #2
Chris,
Thanks! That seemed to make it work as I wanted.

<ch***@cubed-c.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
foreach (RepeaterItem dataItem in RepeaterSchedul es.Items)
{
CheckBox ckDelete =
(CheckBox)dataI tem.FindControl ("CheckBoxSelec ted");
//txtSubscription ID is a <asp:Textbox/> that has
visible=false.
TextBox txtSubscription ID =
(TextBox)dataIt em.FindControl( "txtSubcription ID");
if (ckDelete.Check ed)
{
//delete the item
DoDelete(txtSub criptionID.Text );
}
}

HTH,
Chris

Jan 30 '06 #3
As it happens, I posted a question about this very issue earlier today.

I have a similar bit of code, but if you select more than one checkbox,
and then submit, the code only ever detects the first checkbox that has
been selected and thinks that the rest are unchecked.

Any ideas? If you want to see some code, look in the thread named "How
to get checkbox values form a repeater (looping only finds the first)"
although you'll find the code looks a lot like yours.

TIA
foreach (RepeaterItem dataItem in RepeaterSchedul es.Items)
{
CheckBox ckDelete =
(CheckBox)data Item.FindContro l("CheckBoxSele cted");
//txtSubscription ID is a <asp:Textbox/> that has
visible=fals e.
TextBox txtSubscription ID =
(TextBox)dataI tem.FindControl ("txtSubcriptio nID");
if (ckDelete.Check ed)
{
//delete the item
DoDelete(txtSub criptionID.Text );
}
}

HTH,
Chris


--
Alan Silver
(anything added below this line is nothing to do with me)
Feb 6 '06 #4

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

Similar topics

5
14744
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am trying to delete these lines from the dataview like this: for (int i=0; i < dataView.Count; i++) if (dataGrid.IsSelected(i)) dataView.Delete(i);
5
9178
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within a datagrid do >> not << constitute a set of 'selected' records. Apparently one and only one row may be 'selected' in a datagrid. By selected row I mean the row
0
1358
by: mrwoopey | last post by:
I did not see code for getting all values from a repeater control posted anywhere. So, I figured it out and I am posting for the next person that may need it (sorry if this seems obvious to you): ''''''''''''''''''''''''''''''''''''' Dim strValue As String Dim objCTL As Control For Each objCTL In RepeaterExisting.Controls
1
3835
by: MattB | last post by:
OK, never mind my last post. It was easy enough to refer to the table the repeater is bound to, but I made a big, incorrect assumption in that post. In my last post I thought I was successfully getting values from the textboxes in my repeater. It turns out I am not and I can't see what I'm doing wrong. I've had this problem before and just ended up taking a different route to avoid it. Now I REALLY need to figure out what I'm doing...
0
1195
by: tenaka2k | last post by:
OK I have poked around and have not found an answer to my problem . I have a repeater that in it's <ItemTemplate> calls a function I want to pass the current values from the repeater to the function. I have yet to Figgure out how to get the Evals Data to goto the function as the current code does not work. Producing an error of : "System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used...
2
2110
by: Pete | last post by:
Hi, First, thanks for any time you spend helping me, I'm at a loss. I'm not bit-savvy, so I apologize if this is extremely simple, or I am going about this the wrong way. I am trying to take a byte array and extract some information from that array, and convert it back to a hex value. For instance, I have a byte that I populated from a BinaryReader of a file. Now, lets say it's 4 bytes in length. Out of those 32 bits I need to get...
0
1675
by: bhavika | last post by:
i am fetching table data (2 columns)from database in my JSP Page, There, my first column is checkbox Now as checkbox is checked, that particular row should be selected and should be dislpayed in another table, which is on the same page. I am using ArrayList to get selected rows but i am not able to get whole data which is selected but only one row i am getting Moreover its giving NULLPOINTEREXCEPTION, my code id like this please help me to...
1
4397
by: duane.lortie | last post by:
I'm writing a routine that fetches XML and attempts to parse some values from it. A condensed entry node of the XML looks like this .. <entry> <title>Some title</title> <author> <name>Author</name> </author> <source:resource url="http://somesite.com?tid=123456"/>
12
1913
by: Richard Penfold | last post by:
I am developing an order tracking database, which to keep this explanation simple, consists of 'Orders' table, 'Order Details' table, 'Deliveries' table & 'Inventory' table. There are one-to-many relationships from Orders to 'Order Details, Orders to Deliveries and Orders to Inventory. I have forms to enter and track customer orders and inventory transactions; these work fine but I am having difficulty getting a list-box control to work the...
0
9576
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,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10311
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,...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
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();...
0
5516
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...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2988
bsmnconsultancy
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...

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.