开发者

Dynamic radiobutton set an added listitem as selected

Hi I have a dyna开发者_开发知识库mic radiobutton

aspx-file

<asp:RadioButtonList ID="MoneyTransfer" runat="server" CssClass="darkgrey">
</asp:RadioButtonList>   

aspx.cs-file

MoneyTransfer.Items.Add(new ListItem("BankTransfer","BankTransfer", true));
MoneyTransfer.Items.Add(new ListItem("PayPal","PayPal", true));

What do I have to do to get the first listItem to be the selected one ?


Set Selected Property of listItem to true.

ListItem ls =new ListItem("BankTransfer", "BankTransfer" ,true);
            ls.Selected=true;
            ListItem ls2 = new ListItem("PayPal", "PayPal", true);
            MoneyTransfer.Items.Add(ls);
            MoneyTransfer.Items.Add(ls2); 


Have you tried?

   MoneyTransfer.SelectedIndex = 0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜