有关添加动态控件的问题?

redhat_xu 2005-04-13 11:14:53
为什么RadioButtonList控件放在外面添加动态选项就可以执行,而放在DataList控件或者是Table控件里面就不能执行?
相应代码前台代码:
<asp:datalist id="DataList1" runat="server" Width="100%" Font-Size="Smaller">
<ItemTemplate>
<FONT face="宋体">
<P> </P>
<P> <asp:RadioButtonList id="RadioButtonList1" runat="server" Font-Size="X-Small"></asp:RadioButtonList></P>
</FONT>
</ItemTemplate>
</asp:datalist>
<asp:RadioButtonList id="RadioButtonList2" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 296px" runat="server"></asp:RadioButtonList>
后台代码:
ArrayList MyArray = new ArrayList();
MyArray.Add("1.aaa");
MyArray.Add("2.bbb");
MyArray.Add("3.ccc");
MyArray.Add("4.ddd");
MyArray.Add("5.eee");
MyArray.Add("6.fff");
MyArray.Add("7.ggg");
MyArray.Add("8.hhh");
MyArray.Add("9.iii");
RadioButtonList2.RepeatDirection = RepeatDirection.Horizontal;
RadioButtonList2.DataSource = MyArray;
RadioButtonList2.DataBind();
请问上面这种情况该怎么解决?谢谢!
...全文
94 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
redhat_xu 2005-04-14
  • 打赏
  • 举报
回复
怎么好象不行!

提示找不到对象!怎么回事?
redhat_xu 2005-04-14
  • 打赏
  • 举报
回复
不太明白!

能告诉怎么做吗?
softdeveloper 2005-04-14
  • 打赏
  • 举报
回复
放在datalist里面会生成多项,RadioButtonList的ID就不起作用了,可以通过items[i].Controls数组来找到RadioButtonList控件,然后再操作
hchxxzx 2005-04-14
  • 打赏
  • 举报
回复
将要添加的数据求取出来(DataTable),然后绑定它,就可以了
redhat_xu 2005-04-14
  • 打赏
  • 举报
回复
如果我添加的是动态的选项该怎么做?

也就是每个RadioButtonList里面的项是不一样的,是通过数据库添加的!
Eddie005 2005-04-13
  • 打赏
  • 举报
回复
要在datalist的ItemDataBound事件里写
{
RadioButtonList rblst = e.Item.FindControl("RadioButtonList2") as RadioButtonList;
ArrayList MyArray = new ArrayList();
MyArray.Add("1.aaa");
MyArray.Add("2.bbb");
MyArray.Add("3.ccc");
MyArray.Add("4.ddd");
MyArray.Add("5.eee");
MyArray.Add("6.fff");
MyArray.Add("7.ggg");
MyArray.Add("8.hhh");
MyArray.Add("9.iii");
rblst.RepeatDirection = RepeatDirection.Horizontal;
rblst.DataSource = MyArray;
rblst.DataBind();

}
redhat_xu 2005-04-13
  • 打赏
  • 举报
回复
哦!

我试试!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧