posting radiobuttons inside a gridview do not persist selection after postback..

Discussion in 'ASP .Net' started by Carlos, Nov 15, 2006.

  1. Carlos

    Carlos Guest

    Hi all,

    I have a form with an input radio control in a template field.
    When the user selects an option, and press a button
    the selection disappears.. I would like the selection to
    persist after the button makes the postback,

    I tried using the findcontrol but it returns null, and do not know how
    to make sure that the radio selected persist after the button
    action makes the postback.

    Thanks in advance,

    Carlos.
    Carlos, Nov 15, 2006
    #1
    1. Advertising

  2. Carlos

    kferron Guest

    enable viewstate on the radiobutton control in the template field?

    Carlos wrote:
    > Hi all,
    >
    > I have a form with an input radio control in a template field.
    > When the user selects an option, and press a button
    > the selection disappears.. I would like the selection to
    > persist after the button makes the postback,
    >
    > I tried using the findcontrol but it returns null, and do not know how
    > to make sure that the radio selected persist after the button
    > action makes the postback.
    >
    > Thanks in advance,
    >
    > Carlos.
    kferron, Nov 15, 2006
    #2
    1. Advertising

  3. Carlos

    Carlos Guest

    Thanks, for the reply. However, I already have the enableviewstate set to
    true,
    and the problem is that in this snippet, the control variable comes null.
    i.e. apparently it can not find the control:

    for (int i = 0; i < GridView2.Rows.Count; i++)

    {

    GridViewRow row = GridView11.Rows;

    HtmlInputRadioButton rb =
    (HtmlInputRadioButton)(row.FindControl("rbMonday"));

    if (rb.Checked == true)

    {

    Response.Write("found it..");




    // Column 2 is the name column

    }


    }



    Thanks,



    Carlos.

    "kferron" <> wrote in message
    news:...
    >
    > enable viewstate on the radiobutton control in the template field?
    >
    > Carlos wrote:
    >> Hi all,
    >>
    >> I have a form with an input radio control in a template field.
    >> When the user selects an option, and press a button
    >> the selection disappears.. I would like the selection to
    >> persist after the button makes the postback,
    >>
    >> I tried using the findcontrol but it returns null, and do not know how
    >> to make sure that the radio selected persist after the button
    >> action makes the postback.
    >>
    >> Thanks in advance,
    >>
    >> Carlos.

    >
    Carlos, Nov 15, 2006
    #3
  4. Carlos

    kferron Guest

    Do you have runat="server" in the html radio button?

    Perhaps you could paste the templatefield html.


    Carlos wrote:
    > Thanks, for the reply. However, I already have the enableviewstate set to
    > true,
    > and the problem is that in this snippet, the control variable comes null.
    > i.e. apparently it can not find the control:
    >
    > for (int i = 0; i < GridView2.Rows.Count; i++)
    >
    > {
    >
    > GridViewRow row = GridView11.Rows;
    >
    > HtmlInputRadioButton rb =
    > (HtmlInputRadioButton)(row.FindControl("rbMonday"));
    >
    > if (rb.Checked == true)
    >
    > {
    >
    > Response.Write("found it..");
    >
    >
    >
    >
    > // Column 2 is the name column
    >
    > }
    >
    >
    > }
    >
    >
    >
    > Thanks,
    >
    >
    >
    > Carlos.
    >
    > "kferron" <> wrote in message
    > news:...
    > >
    > > enable viewstate on the radiobutton control in the template field?
    > >
    > > Carlos wrote:
    > >> Hi all,
    > >>
    > >> I have a form with an input radio control in a template field.
    > >> When the user selects an option, and press a button
    > >> the selection disappears.. I would like the selection to
    > >> persist after the button makes the postback,
    > >>
    > >> I tried using the findcontrol but it returns null, and do not know how
    > >> to make sure that the radio selected persist after the button
    > >> action makes the postback.
    > >>
    > >> Thanks in advance,
    > >>
    > >> Carlos.

    > >
    kferron, Nov 15, 2006
    #4
  5. Carlos

    Carlos Guest

    Kevin, thanks again for the continued support.

    Here is my gridview html.

    <asp:GridView ID="GridView2" runat="server" style="left: 7px; position:
    static; top: 116px" AutoGenerateColumns="False" CellPadding="3"
    GridLines="None" Width="230px" BackColor="White" BorderColor="#DEDFDE"
    BorderWidth="0px" CellSpacing="1" >

    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />

    <Columns>

    <asp:TemplateField HeaderText="(Select One">

    <ItemTemplate>

    <input name="rbMonday" type="radio" enableviewstate="true" runat="server"
    value='<%# Eval("payment") %>' />

    </ItemTemplate>

    <HeaderStyle Font-Bold="True" Font-Names="Arial Unicode MS"
    Font-Size="X-Small" BackColor="Black" HorizontalAlign="Left"
    VerticalAlign="Middle" Width="40px" Wrap="False" />

    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="True" />

    </asp:TemplateField>

    <asp:BoundField DataField="payment" HeaderText="Payment" >

    <ItemStyle Font-Bold="True" Font-Names="Arial Unicode MS"
    Font-Size="XX-Small" HorizontalAlign="Left" VerticalAlign="Middle"
    Wrap="True" />

    <HeaderStyle Font-Bold="True" Font-Names="Arial Unicode MS"
    Font-Size="X-Small" BackColor="Black" ForeColor="White"
    HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />

    </asp:BoundField>

    </Columns>

    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />

    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />

    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />

    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />

    </asp:GridView>



    Thanks again,



    Carlos.



    "kferron" <> wrote in message
    news:...
    >
    > Do you have runat="server" in the html radio button?
    >
    > Perhaps you could paste the templatefield html.
    >
    >
    > Carlos wrote:
    >> Thanks, for the reply. However, I already have the enableviewstate set to
    >> true,
    >> and the problem is that in this snippet, the control variable comes null.
    >> i.e. apparently it can not find the control:
    >>
    >> for (int i = 0; i < GridView2.Rows.Count; i++)
    >>
    >> {
    >>
    >> GridViewRow row = GridView11.Rows;
    >>
    >> HtmlInputRadioButton rb =
    >> (HtmlInputRadioButton)(row.FindControl("rbMonday"));
    >>
    >> if (rb.Checked == true)
    >>
    >> {
    >>
    >> Response.Write("found it..");
    >>
    >>
    >>
    >>
    >> // Column 2 is the name column
    >>
    >> }
    >>
    >>
    >> }
    >>
    >>
    >>
    >> Thanks,
    >>
    >>
    >>
    >> Carlos.
    >>
    >> "kferron" <> wrote in message
    >> news:...
    >> >
    >> > enable viewstate on the radiobutton control in the template field?
    >> >
    >> > Carlos wrote:
    >> >> Hi all,
    >> >>
    >> >> I have a form with an input radio control in a template field.
    >> >> When the user selects an option, and press a button
    >> >> the selection disappears.. I would like the selection to
    >> >> persist after the button makes the postback,
    >> >>
    >> >> I tried using the findcontrol but it returns null, and do not know how
    >> >> to make sure that the radio selected persist after the button
    >> >> action makes the postback.
    >> >>
    >> >> Thanks in advance,
    >> >>
    >> >> Carlos.
    >> >

    >
    Carlos, Nov 15, 2006
    #5
  6. Carlos

    kferron Guest

    just quickly perusing your html for the radio button, try making sure
    there is an id.

    <input id="rbMonday" name="rbMonday" type="radio"
    enableviewstate="true" runat="server"> value='<%# Eval("payment") %>'
    />




    Carlos wrote:
    > Kevin, thanks again for the continued support.
    >
    > Here is my gridview html.
    >
    > <asp:GridView ID="GridView2" runat="server" style="left: 7px; position:
    > static; top: 116px" AutoGenerateColumns="False" CellPadding="3"
    > GridLines="None" Width="230px" BackColor="White" BorderColor="#DEDFDE"
    > BorderWidth="0px" CellSpacing="1" >
    >
    > <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
    >
    > <Columns>
    >
    > <asp:TemplateField HeaderText="(Select One">
    >
    > <ItemTemplate>
    >
    > <input name="rbMonday" type="radio" enableviewstate="true" runat="server"
    > value='<%# Eval("payment") %>' />
    >
    > </ItemTemplate>
    >
    > <HeaderStyle Font-Bold="True" Font-Names="Arial Unicode MS"
    > Font-Size="X-Small" BackColor="Black" HorizontalAlign="Left"
    > VerticalAlign="Middle" Width="40px" Wrap="False" />
    >
    > <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="True" />
    >
    > </asp:TemplateField>
    >
    > <asp:BoundField DataField="payment" HeaderText="Payment" >
    >
    > <ItemStyle Font-Bold="True" Font-Names="Arial Unicode MS"
    > Font-Size="XX-Small" HorizontalAlign="Left" VerticalAlign="Middle"
    > Wrap="True" />
    >
    > <HeaderStyle Font-Bold="True" Font-Names="Arial Unicode MS"
    > Font-Size="X-Small" BackColor="Black" ForeColor="White"
    > HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
    >
    > </asp:BoundField>
    >
    > </Columns>
    >
    > <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
    >
    > <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
    >
    > <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
    >
    > <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
    >
    > </asp:GridView>
    >
    >
    >
    > Thanks again,
    >
    >
    >
    > Carlos.
    >
    >
    >
    > "kferron" <> wrote in message
    > news:...
    > >
    > > Do you have runat="server" in the html radio button?
    > >
    > > Perhaps you could paste the templatefield html.
    > >
    > >
    > > Carlos wrote:
    > >> Thanks, for the reply. However, I already have the enableviewstate set to
    > >> true,
    > >> and the problem is that in this snippet, the control variable comes null.
    > >> i.e. apparently it can not find the control:
    > >>
    > >> for (int i = 0; i < GridView2.Rows.Count; i++)
    > >>
    > >> {
    > >>
    > >> GridViewRow row = GridView11.Rows;
    > >>
    > >> HtmlInputRadioButton rb =
    > >> (HtmlInputRadioButton)(row.FindControl("rbMonday"));
    > >>
    > >> if (rb.Checked == true)
    > >>
    > >> {
    > >>
    > >> Response.Write("found it..");
    > >>
    > >>
    > >>
    > >>
    > >> // Column 2 is the name column
    > >>
    > >> }
    > >>
    > >>
    > >> }
    > >>
    > >>
    > >>
    > >> Thanks,
    > >>
    > >>
    > >>
    > >> Carlos.
    > >>
    > >> "kferron" <> wrote in message
    > >> news:...
    > >> >
    > >> > enable viewstate on the radiobutton control in the template field?
    > >> >
    > >> > Carlos wrote:
    > >> >> Hi all,
    > >> >>
    > >> >> I have a form with an input radio control in a template field.
    > >> >> When the user selects an option, and press a button
    > >> >> the selection disappears.. I would like the selection to
    > >> >> persist after the button makes the postback,
    > >> >>
    > >> >> I tried using the findcontrol but it returns null, and do not know how
    > >> >> to make sure that the radio selected persist after the button
    > >> >> action makes the postback.
    > >> >>
    > >> >> Thanks in advance,
    > >> >>
    > >> >> Carlos.
    > >> >

    > >
    kferron, Nov 15, 2006
    #6
  7. Carlos

    Carlos Guest

    Kevin,

    The problem with having the runat="server" in the html radio button, is that
    even though it keeps the selected item, when I select other item(s),
    the other selections remain., and can not be un-selected.

    here is the itemtemplate:

    <ItemTemplate>

    <input name="rbMonday" type="radio" enableviewstate="true" value='<%#
    Eval("song") %>' />

    </ItemTemplate>


    Thanks again

    Carlos

    "kferron" <> wrote in message
    news:...
    >
    > Do you have runat="server" in the html radio button?
    >
    > Perhaps you could paste the templatefield html.
    >
    >
    > Carlos wrote:
    >> Thanks, for the reply. However, I already have the enableviewstate set to
    >> true,
    >> and the problem is that in this snippet, the control variable comes null.
    >> i.e. apparently it can not find the control:
    >>
    >> for (int i = 0; i < GridView2.Rows.Count; i++)
    >>
    >> {
    >>
    >> GridViewRow row = GridView11.Rows;
    >>
    >> HtmlInputRadioButton rb =
    >> (HtmlInputRadioButton)(row.FindControl("rbMonday"));
    >>
    >> if (rb.Checked == true)
    >>
    >> {
    >>
    >> Response.Write("found it..");
    >>
    >>
    >>
    >>
    >> // Column 2 is the name column
    >>
    >> }
    >>
    >>
    >> }
    >>
    >>
    >>
    >> Thanks,
    >>
    >>
    >>
    >> Carlos.
    >>
    >> "kferron" <> wrote in message
    >> news:...
    >> >
    >> > enable viewstate on the radiobutton control in the template field?
    >> >
    >> > Carlos wrote:
    >> >> Hi all,
    >> >>
    >> >> I have a form with an input radio control in a template field.
    >> >> When the user selects an option, and press a button
    >> >> the selection disappears.. I would like the selection to
    >> >> persist after the button makes the postback,
    >> >>
    >> >> I tried using the findcontrol but it returns null, and do not know how
    >> >> to make sure that the radio selected persist after the button
    >> >> action makes the postback.
    >> >>
    >> >> Thanks in advance,
    >> >>
    >> >> Carlos.
    >> >

    >
    Carlos, Nov 20, 2006
    #7
  8. Carlos

    kferron Guest

    well, thats an html issue.. if you want the radio buttons to behave
    correctly you will need to name them all the same thing

    Carlos wrote:
    > Kevin,
    >
    > The problem with having the runat="server" in the html radio button, is that
    > even though it keeps the selected item, when I select other item(s),
    > the other selections remain., and can not be un-selected.
    >
    > here is the itemtemplate:
    >
    > <ItemTemplate>
    >
    > <input name="rbMonday" type="radio" enableviewstate="true" value='<%#
    > Eval("song") %>' />
    >
    > </ItemTemplate>
    >
    >
    > Thanks again
    >
    > Carlos
    >
    > "kferron" <> wrote in message
    > news:...
    > >
    > > Do you have runat="server" in the html radio button?
    > >
    > > Perhaps you could paste the templatefield html.
    > >
    > >
    > > Carlos wrote:
    > >> Thanks, for the reply. However, I already have the enableviewstate set to
    > >> true,
    > >> and the problem is that in this snippet, the control variable comes null.
    > >> i.e. apparently it can not find the control:
    > >>
    > >> for (int i = 0; i < GridView2.Rows.Count; i++)
    > >>
    > >> {
    > >>
    > >> GridViewRow row = GridView11.Rows;
    > >>
    > >> HtmlInputRadioButton rb =
    > >> (HtmlInputRadioButton)(row.FindControl("rbMonday"));
    > >>
    > >> if (rb.Checked == true)
    > >>
    > >> {
    > >>
    > >> Response.Write("found it..");
    > >>
    > >>
    > >>
    > >>
    > >> // Column 2 is the name column
    > >>
    > >> }
    > >>
    > >>
    > >> }
    > >>
    > >>
    > >>
    > >> Thanks,
    > >>
    > >>
    > >>
    > >> Carlos.
    > >>
    > >> "kferron" <> wrote in message
    > >> news:...
    > >> >
    > >> > enable viewstate on the radiobutton control in the template field?
    > >> >
    > >> > Carlos wrote:
    > >> >> Hi all,
    > >> >>
    > >> >> I have a form with an input radio control in a template field.
    > >> >> When the user selects an option, and press a button
    > >> >> the selection disappears.. I would like the selection to
    > >> >> persist after the button makes the postback,
    > >> >>
    > >> >> I tried using the findcontrol but it returns null, and do not know how
    > >> >> to make sure that the radio selected persist after the button
    > >> >> action makes the postback.
    > >> >>
    > >> >> Thanks in advance,
    > >> >>
    > >> >> Carlos.
    > >> >

    > >
    kferron, Nov 21, 2006
    #8
  9. kferron is right...
    Furthermore you can find a number of articles on CodeProject on how to group
    radio buttons on asp.net.

    HTH
    ____________________
    Konstantinos Pantos
    MCP Software Engineer


    "Carlos" <> wrote in message
    news:...
    >
    > Kevin,
    >
    > The problem with having the runat="server" in the html radio button, is
    > that
    > even though it keeps the selected item, when I select other item(s),
    > the other selections remain., and can not be un-selected.
    >
    > here is the itemtemplate:
    >
    > <ItemTemplate>
    >
    > <input name="rbMonday" type="radio" enableviewstate="true" value='<%#
    > Eval("song") %>' />
    >
    > </ItemTemplate>
    >
    >
    > Thanks again
    >
    > Carlos
    >
    > "kferron" <> wrote in message
    > news:...
    >>
    >> Do you have runat="server" in the html radio button?
    >>
    >> Perhaps you could paste the templatefield html.
    >>
    >>
    >> Carlos wrote:
    >>> Thanks, for the reply. However, I already have the enableviewstate set
    >>> to
    >>> true,
    >>> and the problem is that in this snippet, the control variable comes
    >>> null.
    >>> i.e. apparently it can not find the control:
    >>>
    >>> for (int i = 0; i < GridView2.Rows.Count; i++)
    >>>
    >>> {
    >>>
    >>> GridViewRow row = GridView11.Rows;
    >>>
    >>> HtmlInputRadioButton rb =
    >>> (HtmlInputRadioButton)(row.FindControl("rbMonday"));
    >>>
    >>> if (rb.Checked == true)
    >>>
    >>> {
    >>>
    >>> Response.Write("found it..");
    >>>
    >>>
    >>>
    >>>
    >>> // Column 2 is the name column
    >>>
    >>> }
    >>>
    >>>
    >>> }
    >>>
    >>>
    >>>
    >>> Thanks,
    >>>
    >>>
    >>>
    >>> Carlos.
    >>>
    >>> "kferron" <> wrote in message
    >>> news:...
    >>> >
    >>> > enable viewstate on the radiobutton control in the template field?
    >>> >
    >>> > Carlos wrote:
    >>> >> Hi all,
    >>> >>
    >>> >> I have a form with an input radio control in a template field.
    >>> >> When the user selects an option, and press a button
    >>> >> the selection disappears.. I would like the selection to
    >>> >> persist after the button makes the postback,
    >>> >>
    >>> >> I tried using the findcontrol but it returns null, and do not know
    >>> >> how
    >>> >> to make sure that the radio selected persist after the button
    >>> >> action makes the postback.
    >>> >>
    >>> >> Thanks in advance,
    >>> >>
    >>> >> Carlos.
    >>> >

    >>

    >
    >
    Konstantinos Pantos, Nov 21, 2006
    #9
  10. Carlos

    Carlos Guest

    I thank you all for your kind response. However, I believe that
    it does not address the issue. I am using html radiobuttons because
    I read somewhere that it was better because you just need to get
    their values issuing a request.form with the name of the control
    within a template. However, after a postback if a user needs to see
    what it had selected there is no way for the selection to remain.

    My question is if there is an efficient sample somewhere that I can look at.

    Thanks,

    Carlos.

    "Konstantinos Pantos" <> wrote in message
    news:...
    > kferron is right...
    > Furthermore you can find a number of articles on CodeProject on how to
    > group radio buttons on asp.net.
    >
    > HTH
    > ____________________
    > Konstantinos Pantos
    > MCP Software Engineer
    >
    >
    > "Carlos" <> wrote in message
    > news:...
    >>
    >> Kevin,
    >>
    >> The problem with having the runat="server" in the html radio button, is
    >> that
    >> even though it keeps the selected item, when I select other item(s),
    >> the other selections remain., and can not be un-selected.
    >>
    >> here is the itemtemplate:
    >>
    >> <ItemTemplate>
    >>
    >> <input name="rbMonday" type="radio" enableviewstate="true" value='<%#
    >> Eval("song") %>' />
    >>
    >> </ItemTemplate>
    >>
    >>
    >> Thanks again
    >>
    >> Carlos
    >>
    >> "kferron" <> wrote in message
    >> news:...
    >>>
    >>> Do you have runat="server" in the html radio button?
    >>>
    >>> Perhaps you could paste the templatefield html.
    >>>
    >>>
    >>> Carlos wrote:
    >>>> Thanks, for the reply. However, I already have the enableviewstate set
    >>>> to
    >>>> true,
    >>>> and the problem is that in this snippet, the control variable comes
    >>>> null.
    >>>> i.e. apparently it can not find the control:
    >>>>
    >>>> for (int i = 0; i < GridView2.Rows.Count; i++)
    >>>>
    >>>> {
    >>>>
    >>>> GridViewRow row = GridView11.Rows;
    >>>>
    >>>> HtmlInputRadioButton rb =
    >>>> (HtmlInputRadioButton)(row.FindControl("rbMonday"));
    >>>>
    >>>> if (rb.Checked == true)
    >>>>
    >>>> {
    >>>>
    >>>> Response.Write("found it..");
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> // Column 2 is the name column
    >>>>
    >>>> }
    >>>>
    >>>>
    >>>> }
    >>>>
    >>>>
    >>>>
    >>>> Thanks,
    >>>>
    >>>>
    >>>>
    >>>> Carlos.
    >>>>
    >>>> "kferron" <> wrote in message
    >>>> news:...
    >>>> >
    >>>> > enable viewstate on the radiobutton control in the template field?
    >>>> >
    >>>> > Carlos wrote:
    >>>> >> Hi all,
    >>>> >>
    >>>> >> I have a form with an input radio control in a template field.
    >>>> >> When the user selects an option, and press a button
    >>>> >> the selection disappears.. I would like the selection to
    >>>> >> persist after the button makes the postback,
    >>>> >>
    >>>> >> I tried using the findcontrol but it returns null, and do not know
    >>>> >> how
    >>>> >> to make sure that the radio selected persist after the button
    >>>> >> action makes the postback.
    >>>> >>
    >>>> >> Thanks in advance,
    >>>> >>
    >>>> >> Carlos.
    >>>> >
    >>>

    >>
    >>

    >
    Carlos, Nov 21, 2006
    #10
  11. Carlos

    Ulys Guest

    Ulys, Dec 5, 2006
    #11
    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. Grey
    Replies:
    2
    Views:
    595
    Sayed Hashimi
    Sep 7, 2004
  2. Joanne
    Replies:
    2
    Views:
    616
    Joanne
    Jul 7, 2005
  3. =?Utf-8?B?QWlkYXMgUGFzaWxpcw==?=

    Session State doesn't persist after postback (code: C#)

    =?Utf-8?B?QWlkYXMgUGFzaWxpcw==?=, Sep 15, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    6,008
    Bruce Barker
    Sep 15, 2005
  4. Guest

    Gridview and Radiobuttons

    Guest, Apr 28, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    324
    Guest
    Apr 28, 2008
  5. Biguana
    Replies:
    3
    Views:
    472
Loading...

Share This Page