Repeater control checkbox checked event

Discussion in 'ASP .Net' started by c_shah, Jun 6, 2007.

  1. c_shah

    c_shah Guest

    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...
     
    c_shah, Jun 6, 2007
    #1
    1. Advertising

  2. On Jun 6, 9:39 pm, c_shah <> wrote:
    > 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...


    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, Jun 6, 2007
    #2
    1. Advertising

  3. On Jun 6, 10:52 pm, Alexey Smirnov <> wrote:
    > On Jun 6, 9:39 pm, c_shah <> wrote:
    >


    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
     
    Alexey Smirnov, Jun 6, 2007
    #3
  4. c_shah

    c_shah Guest

    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
     
    c_shah, Jun 7, 2007
    #4
  5. On Jun 7, 6:14 pm, c_shah <> wrote:
    > 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


    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
     
    Alexey Smirnov, Jun 7, 2007
    #5
  6. On Jun 7, 11:37 am, Alexey Smirnov <> wrote:
    > On Jun 7, 6:14 pm, c_shah <> wrote:
    >
    >
    >
    >
    >
    > > 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

    >
    > 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- Hide quoted text -
    >
    > - 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 :).
     
    CitrusMotors.com, Jun 15, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew Louden

    checkbox checked change event question

    Matthew Louden, Nov 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    5,431
    Teemu Keiski
    Nov 18, 2003
  2. yurps
    Replies:
    1
    Views:
    6,989
    rajeshthangarasu1983
    Feb 29, 2008
  3. Alan Silver
    Replies:
    2
    Views:
    11,137
    Alan Silver
    Jul 19, 2005
  4. =?Utf-8?B?QW5kcmV3?=

    capturing checkbox.checked in repeater control

    =?Utf-8?B?QW5kcmV3?=, Aug 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,910
    =?Utf-8?B?QW5kcmV3?=
    Aug 23, 2005
  5. randy
    Replies:
    13
    Views:
    480
    Tad McClellan
    Nov 1, 2003
Loading...

Share This Page