ASP.NET中为DataGrid添加单选框
来源:互联网 发布:排球扣球 知乎 编辑:程序博客网 时间:2024/05/16 08:18
使用DataGrid控件添加单选框时,如果直接在模板中加入RadioButton服务器控件,由于.Net的机制,无法将这些RadioButton在客户端出现在同一个组里面。这时我们可以使用Radio标签来实现。
下面是HMTL 页面代码
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<input type="radio" name="rdo" <%# GetChecked(DataBinder.Eval(Container, "DataItem")) %> value='<%# DataBinder.Eval(Container, "DataItem") %>'>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem") %>' ID="Label1">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid><br>
<asp:Button id="btnOk" runat="server" Text="确定"></asp:Button>
<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<input type="radio" name="rdo" <%# GetChecked(DataBinder.Eval(Container, "DataItem")) %> value='<%# DataBinder.Eval(Container, "DataItem") %>'>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem") %>' ID="Label1">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid><br>
<asp:Button id="btnOk" runat="server" Text="确定"></asp:Button>
下面是Page_Load中的数据绑定代码
Dim arr As New ArrayList
arr.Add("新闻综合")
arr.Add("综艺")
arr.Add("电影")
arr.Add("教育")
arr.Add("戏剧")
arr.Add("军事")
arr.Add("体育")
DataGrid1.DataSource = arr
DataGrid1.DataBind()
arr.Add("新闻综合")
arr.Add("综艺")
arr.Add("电影")
arr.Add("教育")
arr.Add("戏剧")
arr.Add("军事")
arr.Add("体育")
DataGrid1.DataSource = arr
DataGrid1.DataBind()
下面是btnOk_Click中获取选择项的代码
Response.Write(Request.Form("rdo"))
下面是设置绑定项中哪个Radio被中的函数
Public Function GetChecked(ByVal str As String) As String
If str = Request.Form("rdo") Then
Return "checked"
Else
Return ""
End If
End Function
If str = Request.Form("rdo") Then
Return "checked"
Else
Return ""
End If
End Function
- ASP.NET中为DataGrid添加单选框
- ASP.NET中为DataGrid添加单选框
- ASP.NET中为DataGrid添加单选框
- ASP.NET中为DataGrid添加合计字段
- ASP.NET中为DataGrid添加合计字段
- ASP.NET中为DataGrid添加合计字段
- ASP.NET中为DataGrid添加合计字段
- ASP.NET中为DataGrid添加合计字段
- ASP.NET中为DataGrid添加合计字段
- ASP.NET中为DataGrid添加合计字段
- 如何在ASP.NET中为DataGrid添加自动编号的功能
- 在ASP.NET中,为你的DataGrid添加背景图片来美化页面
- [ASP.NET]在DataGrid列页眉中添加全选CheckBox
- ASP.NET中DataGrid添加超链接、自定义显示示、页脚汇
- ASP.NET中为DataGrid动态创建模板列
- ASP.NET中为DataGrid动态创建模板列
- Asp.net中把DataTable或DataGrid导出为Excel
- Asp.net中把DataTable或DataGrid导出为Excel
- 获得元素的内容
- 验证码的三种做法[纯数字][纯汉字][字母/数字/汉字混合]C#
- C#字符串的使用笔记
- 我对XNA发布的一些评论和看法
- 《程序员》第9期智慧擂台题目——高频词汇提取
- ASP.NET中为DataGrid添加单选框
- Windows2000/XP系统服务列表及说明
- CSDN style blue
- 利用Lucene制作中文搜尋應用[摘]
- Asp.net(C#)实现验证码功能
- asp.net 性能---asp.net performance
- JFreeChart 开发
- 常用单词
- 深度阅读(评点中国共享软件产业)