开发者

Dynamic radiobutton set an added listitem as selected

开发者 https://www.devze.com 2023-02-24 06:33 出处:网络
Hi I have a dyna开发者_开发知识库mic radiobutton aspx-file <asp:RadioButtonList ID=\"MoneyTransfer\" runat=\"server\" CssClass=\"darkgrey\">

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

精彩评论

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

关注公众号