Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Repeater control checkbox checked event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
c_shah - 06 Jun 2007 20:39 GMT
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
fires on the repeater

Repeater Control Item Template

TextBox
Checkbox1  v
Checkbox2
Label Control

When user checks either of the checkboxes I want to update the label
with new value...
Alexey Smirnov - 06 Jun 2007 21:52 GMT
> using VB.net (2005) ASP.net 2.0
>
[quoted text clipped - 13 lines]
> When user checks either of the checkboxes I want to update the label
> with new value...

You need to add an EventHandler in the ItemCreated event of the
repeater

private void Repeater1_ItemCreated(object sender,
RepeaterItemEventArgs e)
{
RepeaterItem ri=(RepeaterItem)e.Item;

if (ri.ItemType==ListItemType.Item ||
ri.ItemType==ListItemType.AlternatingItem)
{
CheckBox cb=ri.FindControl("Checkbox1") as CheckBox;
cb.CheckedChanged +=new EventHandler(CheckedChanged);
}
}

private void CheckedChanged(object sender, EventArgs e)
{
CheckBox cb=(CheckBox)sender;
if (cb.Checked)
...
}
Alexey Smirnov - 06 Jun 2007 21:58 GMT
Sorry, forgot that you have asked for VB

Private Sub Repeater1_ItemCreated(ByVal sender As Object, ByVal e As
RepeaterItemEventArgs)
Dim ri As RepeaterItem = CType(e.Item, RepeaterItem)
If ri.ItemType = ListItemType.Item Or ri.ItemType =
ListItemType.AlternatingItem Then
Dim cb As CheckBox = CType(ri.FindControl("Checkbox1"), CheckBox)
AddHandler cb.CheckedChanged, AddressOf Me.CheckedChanged
End If
End Sub

Private Sub CheckedChanged(ByVal sender As Object, ByVal e As
EventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
If cb.Checked Then
Label1.Text = "Checked"
else
Label1.Text = ""
End If
End Sub
c_shah - 07 Jun 2007 17:14 GMT
Alexy, thank you.

I  have another question. I would appreciate if you can answer my
question.

ItemTemplate of a repeater has two checkboxes and a label. (each
checbox is an option) and label control  will display price. if one or
both the checkboxes is checked price need to be updated on the lable.
solution you proviced will not as I bound repeater with a datasset
(few rows) So for each row in my dataset i have have two checkboxes
and a label.

each row will have checkboxes and price label

i only want to update label (for which checkbox is checked)..

I guess I have to iterate through the number of items bound to
repeater and find out which row is checked and update label for that
item

any code help
Alexey Smirnov - 07 Jun 2007 19:37 GMT
> Alexy, thank you.
>
[quoted text clipped - 17 lines]
>
> any code help

What's the purpose of that repeater? Using the CheckedChanged event
you will postback the page each time. If you don't update the
datasource the postback makes no sense for me. If the label depends on
checkboxes only, you can change its text using a client js. Otherwise
you have to iterate through the items, I think
CitrusMotors.com - 15 Jun 2007 23:42 GMT
> > Alexy, thank you.
>
[quoted text clipped - 25 lines]
>
> - Show quoted text -

You could also put a field somewhere in the repeater that you could
use to fund your items unique ID, to go perform another function on
that item.
to keep it simple, say one of the labels is a record id.

an example is what I use for data grids:
           CheckBox myCheckBox = (CheckBox)sender;
           GridViewRow dgi;

           dgi = (GridViewRow)myCheckBox.Parent.Parent;
           string sInvoiceItemID = dgi.Cells[1].Text.Trim();
           Trace.Write(sInvoiceItemID);

theMethodTodoRealWork( sInvoiceItemID);

you have identified the item they checked, now perform the operation
on it

a full article that showed me this: http://aspnet.4guysfromrolla.com/articles/052406-1.aspx
there is also some stuff over at codeproject.com. Do a search for
checkboxes

If you already figured it out, then this is just long term storage for
me and the next time I forget how to do this :).

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.