GridView绑定radiobutton以后实现唯一选择,互斥
<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/" />";
}
}