SETTING RADIOBUTTONLIST SELECTED VALUE

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
C#  .NET 
 876  View(s)
Ratings:
Rate this:

I am trying to select the radiobuttonlist's using the following code but it never get selected.

<asp:RadioButtonList ID="rdBond" CssClass="RadioButtonList"

                            runat="server" RepeatDirection="Horizontal">

                            <asp:ListItem>Yes</asp:ListItem>

                            <asp:ListItem>No</asp:ListItem>

                        </asp:RadioButtonList>

and I tried both of the follwing methods but doesn't work.

       ListItem l2 = rdOffset.Items.FindByValue(cd.BondReq.ToString());

        if (l2 != null)

            l2.Selected = true;

 

        rdOffset.SelectedValue = cd.Offset.ToString();

Please help to fix it.

  1. Samuel Fernandes

    Post:159

    Points:1117
    Re: Setting RadioButtonList selected value

    Make this change :

      <asp:RadioButtonList ID="rdBond" CssClass="RadioButtonList"

                                runat="server" RepeatDirection="Horizontal">

                                <asp:ListItem Selected =True >Yes</asp:ListItem> <%--change this in your code--%>

                                <asp:ListItem>No</asp:ListItem>

                            </asp:RadioButtonList>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!