Default Checked value for radiobutton based on data

cthang

Member
Joined
Feb 10, 2009
Messages
8
Programming Experience
Beginner
Hi,

I have a radiobuttonlist and would like to have one of the radio buttons checked based on the grade a sql table. So if a student is in grade 10 then the radio button Grade 10 would be checked .

Here is my radiobuttonlist:

Code:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Width="355px" 
            AutoPostBack="True" RepeatDirection="Horizontal" Checked=<%# Container.DataItem("grade") %>

            <asp:ListItem Value="09">Grade 9</asp:ListItem>
            <asp:ListItem Value="10" >Grade 10</asp:ListItem>
            <asp:ListItem Value="11">Grade 11</asp:ListItem>
            <asp:ListItem Value="12">Grade 12</asp:ListItem>
        </asp:RadioButtonList>
Thanks
 

MattP

Well-known member
Joined
Feb 29, 2008
Messages
1,206
Location
WY, USA
Programming Experience
5-10
Try something like this:

Code:
<asp:RadioButtonList ... SelectedValue='<%# Bind("grade") %>'>
 

cthang

Member
Joined
Feb 10, 2009
Messages
8
Programming Experience
Beginner
thanks for the reply.

I tried that before and it still does not select the radio button.
 
Top Bottom