如何使用Items.Add(Item)动态添加单选按钮中的项目 [英] How Do I Add Items In Radio Button Dynamically Using Items.Add(Item)

查看:788
本文介绍了如何使用Items.Add(Item)动态添加单选按钮中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用代码动态添加单选按钮列表项,我收到此错误:



'System.Web.UI.WebControls.RadioButton'不包含'Items'的定义并且没有扩展方法'items'接受类型'System.Web.UI.WebControls.RadioButton'的第一个参数可以找到(你是否缺少using指令或汇编引用?)

我的代码是:

< asp:RadioButton ID =lstBorderrunat =serverWidth =177pxHeight =59px/>





protected void Page_Load(object sender,EventArgs e)

{

if(!this。 IsPostBack)

{

ListItem item = new ListItem();

item.Text = BorderStyle.None.ToString();

item.Value =((int)BorderStyle.None).ToString();

lstBorder.Items.Add(item);

}

}



如果你能帮助我,我将不胜感激。如果Items不是单选按钮列表中的属性,我甚至没有得到该部分?我怎么能解决它?

解决方案

我认为你必须使用radiobuttonlist而不是radiobutton

检查以下链接它有属性项



https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist(v = vs.110).aspx [ ^

I tried to add radio button list items dynamically with code and i got this error:

'System.Web.UI.WebControls.RadioButton' does not contain a definition for 'Items'and no extension method 'Items' accepting a first argument of type 'System.Web.UI.WebControls.RadioButton' could be found (are you missing a using directive or an assembly reference?)
my code is:
<asp:RadioButton ID="lstBorder" runat="server" Width="177px" Height="59px" />


protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ListItem item = new ListItem();
item.Text = BorderStyle.None.ToString();
item.Value = ((int)BorderStyle.None).ToString();
lstBorder.Items.Add(item);
}
}

I would appreciate if you could help me. I even didnt get the part if Items is not a property in radio button list? how could i fix it?

解决方案

I think u have to use radiobuttonlist instead of radiobutton
check below link it has property items

https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist(v=vs.110).aspx[^]


这篇关于如何使用Items.Add(Item)动态添加单选按钮中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆