All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
ASP.NET中为DataGrid添加单选框_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/10 6:27:43 Browse times: 330 Comment times: 0

ASP.NET中为DataGrid添加单选框_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

ASP.NET中为DataGrid添加单选框_[Asp.Net教程]  使用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>
  下面是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()
  下面是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

来源:网络





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.