1.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>GridView中的Radio</title>
</head>
<body>
    
<form id="form1" runat="server">
        
<div>
            
<asp:GridView ID="GridView1" Width="100%" runat="server" AutoGenerateColumns="false">
                
<Columns>
                    
<asp:TemplateField>
                        
<HeaderTemplate>
                            单选
</HeaderTemplate>
                        
<ItemTemplate>
                            
<input type="radio" id="RadioName" name="RadioName" value='<%# Eval("au_id")%>'/>
                        
</ItemTemplate>
                    
</asp:TemplateField>
                    
<%--<asp:BoundField DataField="au_id" HeaderText="au_id" />--%>
                    
<asp:BoundField DataField="au_lname" HeaderText="au_lname" />
                    
<asp:BoundField DataField="au_fname" HeaderText="au_fname" />
                    
<asp:BoundField DataField="phone" HeaderText="phone" />
                    
<asp:BoundField DataField="address" HeaderText="address" />
                
</Columns>
            
</asp:GridView>
            
<asp:Button ID="Button1" runat="server" Text="显示" OnClick="Button1_Click" /></div>
    
</form>
</body>
</html>
2.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GridView_GridView_Radio : System.Web.UI.Page
{
    Practice.DAL.authors authorsbll 
= new Practice.DAL.authors();

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            DataBindGridView();
        }

    }


    
/// <summary>
    
/// 功    能:绑定GridView
    
/// 作  者:PUKE
    
/// 完成时间:2007-05-18
    
/// 版  权:pukesys@tom.com
    
/// </summary>

    private void DataBindGridView()
    
{
        DataSet ds 
= authorsbll.GetList("");
        GridView1.DataSource 
= ds;
        GridView1.DataBind();
    }

    
/// <summary>
    
/// 功    能:Button1的Click,获得选中的数据的id值
    
/// 作  者:PUKE
    
/// 完成时间:2007-05-18
    
/// 版  权:pukesys@tom.com
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void Button1_Click(object sender, EventArgs e)
    
{
        Response.Write(Request.Form.Get(
"RadioName"));
    }

}

posted on 2007-06-02 13:52  秦岭过客  阅读(774)  评论(0编辑  收藏  举报