很烦恼的问题:怎样给RadioButtonList控件里面的每个input加个onClick(客户端的)属性
如题……
一直没有找到有效地解决方案,请高手指点……
问题点数:50、回复次数:10Top
1 楼fsonly(FSG)回复于 2004-08-03 08:58:45 得分 20
呵呵,在绑定的时候加Attribs即可Top
2 楼xuhengzhang(章郎)回复于 2004-08-03 08:59:57 得分 0
顶一下,我在线等……Top
3 楼triout(笨牛)回复于 2004-08-03 09:02:28 得分 10
一楼告诉你了呀
在绑定时对ButtonList的数据绑定事件编程,对每个ListItem添加一个Attributes["onclick"]="client代码"
或在绑定后,遍历ButtonList的每个ListItem使用上面的方式添加。Top
4 楼xuhengzhang(章郎)回复于 2004-08-03 09:03:47 得分 0
服务器端:
<asp:RadioButtonList id="rblType" runat="server" RepeatDirection="Horizontal" CellPadding="0" CellSpacing="0">
<asp:ListItem Value="0" Selected="True">站点</asp:ListItem>
<asp:ListItem Value="1">目录</asp:ListItem>
</asp:RadioButtonList>
解析到客户端后:
<table id="rblType" cellspacing="0" cellpadding="0" onClick="XXXXXXX" border="0" style="border-collapse:collapse;">
<tr>
<td><input id="rblType_0" type="radio" name="rblType" value="0" checked="checked" /><label for="rblType_0">站点</label></td>
<td><input id="rblType_1" type="radio" name="rblType" value="1" /><label for="rblType_1">目录</label></td>
</tr>
</table>
所以在服务器端用Attributes.Add加上去的属性解析到客户端之后不是在<input>标签上,而是在<table>标签上Top
5 楼xuhengzhang(章郎)回复于 2004-08-03 09:08:01 得分 0
To: triout(笨牛) ,你的意思是下面这样吗?
rblType.Items[0].Attributes.Add("onClick","alert('aaaaaaa');");
可是我已经着尝试过了,根本没有加上去任何东西。不知道什么原因?Top
6 楼Namo(烟燃和鱼)回复于 2004-08-03 09:09:06 得分 20
你的List是动态生成的吗?如果不是,那么先写好Input的Onclick属性,然后Input是动态生成的也能使用。如果连List都是动态生成的,那么确实比较麻烦,一般你要在Page_Load前设置这个属性。所以最好慎用,.Net和以前的ASP不通,这个页面机制比较麻烦,遇到这些问题其实可以试试在aspx文件中使用Javascript + html的方式动态生成控件(前提是基于html的基本控件)。Top
7 楼Namo(烟燃和鱼)回复于 2004-08-03 09:11:42 得分 0
可以参考这里:
http://community.csdn.net/Expert/topic/3216/3216800.xml?temp=.3563806Top
8 楼xuhengzhang(章郎)回复于 2004-08-03 09:12:37 得分 0
我的rblType不是动态生成的,就是下面这样的:
<asp:RadioButtonList id="rblType" runat="server" RepeatDirection="Horizontal" CellPadding="0" CellSpacing="0">
<asp:ListItem Value="0" Selected="True">站点</asp:ListItem>
<asp:ListItem Value="1">目录</asp:ListItem>
</asp:RadioButtonList>Top
9 楼xuhengzhang(章郎)回复于 2004-08-03 09:23:29 得分 0
到底有没有人能解决?Top
10 楼xuhengzhang(章郎)回复于 2004-08-03 09:42:04 得分 0
ListItem到底能不能加上attributes,如果能,请给出具体的代码,谢谢……Top




