repeater和radiobutton的问题

sanjiawan 2011-01-19 09:25:53
我想有经验的人看了题目就能联想到可能提到的问题(我菜鸟)
如何让radiobutton可以实现单选 现在repeater里面的所有radiobutton都可以选 郁闷




PS:说加groudname的人就免了 不要说了
说用<input type="radio">的人 请提供实现具体的方法(可以不完全) 谢谢
...全文
131 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanjiawan 2011-01-19
  • 打赏
  • 举报
回复
laowang134
你去试试begintransaction
的代码 就明白要实现什么功能了 我似乎也说清楚了
laowang134 2011-01-19
  • 打赏
  • 举报
回复
楼主是想要全repeater中只能选中一个?而不是每项只能选中一个?
是不是这种。。

<table>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td><%#Eval("Areaname") %></td>
<td> <asp:RadioButton ID="rdb1" runat="server" AutoPostBack="true" oncheckedchanged="RadioButton2_CheckedChanged"/>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>



protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
RadioButton rdb = sender as RadioButton;
RepeaterItem item = rdb.Parent as RepeaterItem;
int count = Repeater1.Items.Count;
for (int i = 0; i < count; i++)
{
RadioButton rdb1 = Repeater1.Items[i].FindControl("rdb1") as RadioButton;
if (i != item.ItemIndex)
{
rdb1.Checked = false;
}
}
}
sanjiawan 2011-01-19
  • 打赏
  • 举报
回复
begintransaction
爱死你了
begintransaction 2011-01-19
  • 打赏
  • 举报
回复
function allSelect()
{
var items=document.getElementByTagName("input");
for(var i=0,len<items.Length;i<len;i++)
{
if(items[i].type=="radio" && items[i].name=="aa")
{
items[i].checked=true;
}
}
}
sanjiawan 2011-01-19
  • 打赏
  • 举报
回复
laowang134
估计你没用过这种组合吧 不过还是谢谢你的热心
sanjiawan 2011-01-19
  • 打赏
  • 举报
回复
xuliangcoolove@163.com


a471278829
谢谢哈
sisi88 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 laowang134 的回复:]

....
HTML code

<input id="Radio1" type="radio" name="aa" />
<input id="Radio2" type="radio" name="aa" />
<input id="Radio3" type="radio" name="aa" />
<input id="Radio4" typ……
[/Quote]
同意2樓
a471278829 2011-01-19
  • 打赏
  • 举报
回复
昨天有个朋友 遇到跟你相同的问题 问过我了
要想在循环里面 让你的 单选按钮 实现单选效果
好像只有用js 我给那个朋友的解决方案就是 用JS
你邮箱多少 我发给你DEMO
我QQ471278829 用服务器语言的方式好像的确不行 因为
在 repeater 项模版循环的时候 就处理过了 所以 groudname没有效果了
laowang134 2011-01-19
  • 打赏
  • 举报
回复
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="aa" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="aa"/>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="aa"/>
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="aa"/>
laowang134 2011-01-19
  • 打赏
  • 举报
回复
....

<input id="Radio1" type="radio" name="aa" />
<input id="Radio2" type="radio" name="aa" />
<input id="Radio3" type="radio" name="aa" />
<input id="Radio4" type="radio" name="aa" />
laowang134 2011-01-19
  • 打赏
  • 举报
回复
gourpname="";
设置一样groupname的只能选择其中一个。。

62,046

社区成员

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

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

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

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