日期:2014-05-18  浏览次数:20485 次

郁闷!!!!!请高手解答
对于一个CheckBoxList   ,我需要这样显示:
    view   +=   @ " <asp:CheckBoxList   ID=Answer   runat= 'server '> <asp:ListItem   Value=A> A </asp:ListItem> </asp:CheckBoxList> ";
  Response.Write(view);
    它只出现一个A,而没有选择框,这是怎么回事啊?另外,这样动态显示后如何取得CheckBoxList   的值呢?



------解决方案--------------------
路过,帮顶一下
------解决方案--------------------
Response.Write不能输出服务器端控件。只能输入客户端html代码

要加载服务器端控件,就这样:
CheckBoxList cbl = new CheckBoxList();
cbl.Items.Add(new ListItem( "A ", "A "));
Page.Controls.Add(cbl);



------解决方案--------------------
<%@ Page language= "c# " Debug= "true " %>
<HTML>
<HEAD>
<script runat= "server ">
void Page_Load(object sender, System.EventArgs e)
{
Control c = ParseControl( " <asp:button text= 'Click here! ' runat= 'server ' /> ");
myPlaceholder.Controls.Add(c);
}
</script>
</HEAD>
<body>
<form runat=server>
<asp:placeholder id = myPlaceholder runat=server />
</form>
</body>
</HTML>


------解决方案--------------------
你生成的控件方式有问题,你觉得asp标记的控件在HTML能显式出来么?

转换为HTML中的控件标记即可 <input...
------解决方案--------------------
不能这样写的,服务器端控件展示在客户端旧不是这个样子了!
------解决方案--------------------
CheckBoxList cbl = new CheckBoxList();
cbl.id= "cbl1 "
cbl.Items.Add(new ListItem( "A ", "A "));
Page.Controls.Add(cbl);

// 取值
CheckBoxList c = (CheckBoxList )Page.FindControl( "cbl1 ");
//这样就取到了动态添加的CheckBoxList
------解决方案--------------------
可以用Request取得