您的位置:首页 > 其它

GridView绑定radiobutton以后实现唯一选择,互斥

2010-03-19 10:57 369 查看
<asp:GridView ID="GridView1" runat="server" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound">

<Columns>
<asp:TemplateField>
<ItemTemplate>
 
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="tester" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
是不能实现排斥的
因为radiobutton的排斥在html中实际上就是name值相同的radion会相互排斥
但是在gridview中的radionbutton的name值是会被默认修改为
<input id="GridView1_ctl02_RadioButton2" type="radio" name="GridView1$ctl02$tester" value="RadioButton2" />
name会被改变 = =#

这样可以解决
<asp:GridView ID="GridView1" runat="server" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound">

<Columns>
<asp:TemplateField>
<ItemTemplate>
  
<asp:Label ID="Label2" runat="server" Text="Label"> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow g = e.Row;
Label lab=(Label) g.Cells[0].FindControl("Label2");
if (lab != null)
{
lab.Text = " <input id=/""+lab.ClientID+"/" type=/"radio/" name=/"RadioButton1/" value=/"1/" />";
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐