日期:2012-05-23  浏览次数:20436 次

#region 声明
//----------------------------------------------------------------------
//
// 作者: 李淼(Nick.Lee)
//
// ASP.net下DataGrid的单项选择控件

// 时间:2005-3-15

// boyorgril@msn.com
// QQ:16503096
//注意:引用请标明出处,谢谢
//----------------------------------------------------------------------
#endregion



前台:

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="WebUserControl1.ascx.cs" Inherits="message1.WebUserControl1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<LINK href="xpTable.css" type="text/css" rel="stylesheet">
<asp:DataGrid id="DataGrid1" runat="server" BorderStyle="None" BorderWidth="1px" CellPadding="4"
Font-Size="9pt" Width="70%" BorderColor="#3366CC">
<SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
<ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
<FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
 <INPUT type=radio value='<%# DataBinder.Eval(Container.DataItem, "Volume")%>' name=RadioName>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button><INPUT id="rd" type="hidden" name="rd" runat="server">
<asp:Label id="Label1" runat="server">Label</asp:Label>


后台:

namespace message1
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.ComponentModel;

using NickLee.Web.UI;

/// <summary>
/// WebUserControl1 的摘要说明。
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.HtmlControls.HtmlInputHidden rd;
protected System.Web.UI.WebControls.Label Label1;
public DataSet custDS = new DataSet();
protected System.Web.UI.WebControls.Button Button1;

private string sql;
public string Sql
{
get{return sql;}
set{sql=value;}
}

//------------------------------------------------------------------------------------
/// <summary>
/// 窗体名
/// </summary>
System.Web.UI.Page _page;
[BrowsableAttribute(true),CategoryAttribute("Appearance"),BindableAttribute(true)]
public System.Web.UI.Page page
{
get
{
return _page;
}
set
{
_page=value;
}
}

private void Page_Load(object sender, System.EventArgs e)
{
string js = "";
// js+="<script>\r\n";
js+="function ld(){\r\n";
js+="for(i=0;i<document.getElementsByName('RadioName').length;i++)\r\n";
js+="if(document.getElementsByName('RadioName')[i].value==";
js+="document.getElementById('" + rd