473,503 Members | 1,648 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="Middle" />
<asp:LinkButton ID="LinkButtonDelete" runat="server"
OnClick="LinkButtonDelete_Click" ToolTip="Delete">Delete</asp:LinkButton>
<br />
<asp:Repeater ID="RepeaterSchedules" runat="server"
OnItemCommand="RepeaterSchedules_ItemCommand">
<HeaderTemplate>
<table>
<tr class="headerrow">
<td align="center" valign="middle">
<asp:CheckBox
ID="CheckBoxSelectedHeader" runat="server" AutoPostBack="True"
OnCheckedChanged="CheckBoxSelectedHeader_CheckedCh anged" />
</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="background-color: #EEEEEE">
<asp:CheckBox ID="CheckBoxSelected"
runat="server" />
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<asp:LinkButton ID="LinkButtonEdit"
runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem,
"SubscriptionID")%>'>Edit</asp:LinkButton>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"Report") %>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"Path") %>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"Description")%>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"LastExecuted") %>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"Status") %>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"Owner")%>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"ModifiedBy")%>
</td>
<td align="center" valign="middle"
style="background-color: #EEEEEE">
<%# DataBinder.Eval(Container.DataItem,
"ModifiedDate")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
..aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BuildSchedulesList();
}
}

private void BuildSchedulesList()
{
System.Data.DataTable tbl = new System.Data.DataTable("Schedules");
System.Data.DataColumn colSubscriptionID =
tbl.Columns.Add("SubscriptionID", typeof(string));
System.Data.DataColumn colReport = tbl.Columns.Add("Report",
typeof(string));
System.Data.DataColumn colPath = tbl.Columns.Add("Path",
typeof(string));
System.Data.DataColumn colDescription =
tbl.Columns.Add("Description", typeof(string));
System.Data.DataColumn colLastExecuted =
tbl.Columns.Add("LastExecuted", typeof(System.DateTime));
System.Data.DataColumn colStatus = tbl.Columns.Add("Status",
typeof(string));
System.Data.DataColumn colOwner = tbl.Columns.Add("Owner",
typeof(string));
System.Data.DataColumn colModifiedBy = tbl.Columns.Add("ModifiedBy",
typeof(string));
System.Data.DataColumn colModifiedDate =
tbl.Columns.Add("ModifiedDate", typeof(System.DateTime));

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

row["SubscriptionID"] = subscription.SubscriptionID;
row["Report"] = subscription.Report;
row["Path"] = subscription.Path;
row["Description"] = subscription.Description;
row["LastExecuted"] = subscription.LastExecuted;
row["Status"] = subscription.Status;
row["Owner"] = subscription.Owner;
row["ModifiedBy"] = subscription.ModifiedBy;
row["ModifiedDate"] = subscription.ModifiedDate;

tbl.Rows.Add(row);
}
}

this.RepeaterSchedules.DataSource = tbl;
this.RepeaterSchedules.DataBind();
}

protected void RepeaterSchedules_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
// Get the SubscriptionID
Response.Write(e.CommandArgument.ToString());
}

protected void LinkButtonDelete_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.RepeaterSchedules.Items.Count; i++)
{
System.Web.UI.WebControls.CheckBox cb =
(System.Web.UI.WebControls.CheckBox)this.RepeaterS chedules.Items[i].FindCont
rol("CheckBoxSelected");

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 7786
foreach (RepeaterItem dataItem in RepeaterSchedules.Items)
{
CheckBox ckDelete =
(CheckBox)dataItem.FindControl("CheckBoxSelected") ;
//txtSubscriptionID is a <asp:Textbox/> that has
visible=false.
TextBox txtSubscriptionID =
(TextBox)dataItem.FindControl("txtSubcriptionID");
if (ckDelete.Checked)
{
//delete the item
DoDelete(txtSubcriptionID.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.googlegr oups.com...
foreach (RepeaterItem dataItem in RepeaterSchedules.Items)
{
CheckBox ckDelete =
(CheckBox)dataItem.FindControl("CheckBoxSelected") ;
//txtSubscriptionID is a <asp:Textbox/> that has
visible=false.
TextBox txtSubscriptionID =
(TextBox)dataItem.FindControl("txtSubcriptionID");
if (ckDelete.Checked)
{
//delete the item
DoDelete(txtSubcriptionID.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 RepeaterSchedules.Items)
{
CheckBox ckDelete =
(CheckBox)dataItem.FindControl("CheckBoxSelected" );
//txtSubscriptionID is a <asp:Textbox/> that has
visible=false.
TextBox txtSubscriptionID =
(TextBox)dataItem.FindControl("txtSubcriptionID") ;
if (ckDelete.Checked)
{
//delete the item
DoDelete(txtSubcriptionID.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
14714
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...
5
9165
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...
0
1343
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): ...
1
3802
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...
0
1186
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...
2
2093
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...
0
1650
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...
1
4375
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>...
12
1875
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...
0
7319
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...
1
6979
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...
0
7449
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
5570
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
4666
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...
0
3160
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...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
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 ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.