Reputation: 89
How can i set each list item value dynamically in radio button list?
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:RadioButtonList>
In above radio button list the list items i want to set from database.
your help will be highly appreciated.
Upvotes: 0
Views: 6266
Reputation: 47
You must find ListItem by text and change it. Let's think, you have control :
<asp:RadioButtonList ID="yourrdblist" runat="server" RepeatDirection="Horizontal" AutoPostBack="true" CssClass="tarpiukai">
<asp:ListItem Selected="True" Value="0" Text="0"></asp:ListItem>
<asp:ListItem Value="0" Text="1"></asp:ListItem>
<asp:ListItem Value="1" Text="2"></asp:ListItem>
</asp:RadioButtonList>
In this case you can easy change value of ListItem with text "1" to text "bambargija" :
yourrdblist.Items.FindByText("1").Text = "bambargija";
Upvotes: 1
Reputation: 4170
Like this:
<asp:RadioButtonList ID="inputs" runat="server" Width="50px">
</asp:RadioButtonList>
..and...
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
inputs.Items.Add("input1");
inputs.Items.Add("input2");
inputs.Items.Add("input3");
inputs.Items.Add("input4");
}
}
Upvotes: 0
Reputation: 1095
That's easy. Have a look at the basiscs of the RadioButtonList-Control.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist.aspx
If you wanna have access to the inner controls, the ListItems then acces them by using the controls property Items.
Greetings,
Upvotes: 0