以编程方式更改列表项

时间:2012-11-29 11:26:15

标签: c# asp.net radio-button

目前我正在使用asp.net创建列表

<asp:RadioButtonList ID="formatOfReport" runat="server" Font-Size="Large" 
                  BorderColor="Black" 
                  onselectedindexchanged="formatOfReport_SelectedIndexChanged" 
                  style="width: 124px">
                  <asp:ListItem Selected="True">k</asp:ListItem>
                <asp:ListItem>j</asp:ListItem>

            </asp:RadioButtonList>

我是c#的新手,想知道如何以编程方式设置列表项,因为它们在上面

1 个答案:

答案 0 :(得分:1)

例如来自page_load

protected void Page_Load(object sender, EventArgs e)
{                        
    if(!IsPostBack)
    {
       var item = new ListItem("k", "k");
       item.Selected = true;
       this.formatOfReport.Items.Add(item);
       item  = new ListItem("j", "j")
       this.formatOfReport.Items.Add(item);
    }
}