GridView绑定radiobutton以后实现唯一选择,互斥
2010-03-19 10:57
405 查看
<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/" />";
}
}
<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/" />";
}
}
相关文章推荐
- GridView绑定radiobutton以后实现唯一选择,互斥
- GridView绑定radiobutton以后实现唯一选择,互斥
- 扩展RadioButton,实现在不同容器中互斥选择
- DataGrid模版列中的radiobutton不能实现唯一选择,怎么办?
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参(selected的值和页面其它元素的值)
- gridview中radiobutton实现单选
- 类似淘宝购物时,尺寸,颜色选择的radiobutton样式,android总怎么实现
- datagrid GridView Repeater 绑定 序号 逐一递增的实现
- 八、初学.NET—GridView 中实现每一行的编辑、删除和更新语句,并且编辑模式绑定下拉框或者单选框。
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参
- GridView中实现单选RadioButton
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参
- 【原创】使用GridView实现绑定List并排序
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参(selected的值和页面其它元素的值)以及js的select
- Gridview中实现RadioButton单选效果
- Asp.net使用jQuery实现Gridview, Repeater异步绑定数据
- gridview绑定checkbox控件后,通过单击CheckedChanged事件获取当前选择行的数据
- [置顶] gridview中嵌套gridview(并实现子gridview的数据绑定),页面传值,加密,数据绑定
- GridView中给DropDownList动态绑定数据,及选择列表值后自动更新数据库
- listview中内嵌gridview实现子菜单选择效果