Attaching a value to RadioButtons in a Repeater

Discussion in 'ASP .Net Web Controls' started by JesperGJensen, Feb 4, 2008.

  1. I need to select a date from a list of possible dates. I do this
    through a Repeater

    <asp:Repeater>
    <ItemTemplate>
    <RadioButton OnCheckedChanged="rptSelect_Changed">
    <asp:Label> a date </asp:Label>
    </ItemTemplate
    </asp:Repeater>

    In my current testcase there are 7 days to choose from. I use the
    rptSelect_Changed function to handle the selection Serverside.
    But how do i attach the date information to each RadioButton?
    Currently i can only get basic RadioButton object. But this
    radiobutton object does not know which date it represents.
    When i did something similar with LinkButtons in a repeater i used
    CommandArgument to attach the information.

    How do i attach information to a radiobutton in this setup?
     
    JesperGJensen, Feb 4, 2008
    #1
    1. Advertising

  2. Hi Jesper,

    Try using the following code. In this sample, I find the parent control of
    the RadioButton and get the Label placed in the same parent control. You can
    access other child controls you may want to add in case you need to store
    some other data inside them. (I haven't tried executing the code)

    <asp:Repeater>
    <ItemTemplate>
    <RadioButton ID="rbDate" runat="server"
    OnCheckedChanged="rptSelect_Changed">
    <asp:Label ID="lbDate" runat="server"> a date </asp:Label>
    </ItemTemplate
    </asp:Repeater>


    protected void rptSelect_Changed(object sender, EventArgs e)
    {
    RadioButton m_RB = (RadioButton)sender;
    RepeaterItem m_RI = (RepeaterItem)m_RB.Parent;
    Label m_L = (Label)m_RI.FindControl("lbDate");
    string m_DateString = m_L.Text;
    }

    --
    All the best,
    Coskun SUNALI
    MVP ASP/ASP.NET
    http://sunali.com
    http://www.propeople.dk


    "JesperGJensen" <> wrote in message
    news:...
    >I need to select a date from a list of possible dates. I do this
    > through a Repeater
    >
    > <asp:Repeater>
    > <ItemTemplate>
    > <RadioButton OnCheckedChanged="rptSelect_Changed">
    > <asp:Label> a date </asp:Label>
    > </ItemTemplate
    > </asp:Repeater>
    >
    > In my current testcase there are 7 days to choose from. I use the
    > rptSelect_Changed function to handle the selection Serverside.
    > But how do i attach the date information to each RadioButton?
    > Currently i can only get basic RadioButton object. But this
    > radiobutton object does not know which date it represents.
    > When i did something similar with LinkButtons in a repeater i used
    > CommandArgument to attach the information.
    >
    > How do i attach information to a radiobutton in this setup?
     
    Coskun SUNALI [MVP], Feb 5, 2008
    #2
    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. Sean
    Replies:
    1
    Views:
    374
    Ken Cox [Microsoft MVP]
    Aug 6, 2003
  2. RB

    RadioButtons & DataGrid

    RB, Aug 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    410
  3. Simon
    Replies:
    1
    Views:
    397
    Teemu Keiski
    May 17, 2004
  4. =?Utf-8?B?Q2hyaXN0aWFhbiBOaWV1d2xhYXQ=?=

    Dynamically add RadioButtons in Repeater

    =?Utf-8?B?Q2hyaXN0aWFhbiBOaWV1d2xhYXQ=?=, May 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    961
    =?Utf-8?B?Q2hyaXN0aWFhbiBOaWV1d2xhYXQ=?=
    May 26, 2005
  5. Sachin
    Replies:
    1
    Views:
    1,196
    sloan
    Feb 21, 2006
Loading...

Share This Page