关于RadioButtonList的问题
<asp:RadioButtonList id="PayType" runat="server" Width="120px"><asp:ListItem Value="1"> 现金支付</asp:ListItem><asp:ListItem Value="2"> E币支付</asp:ListItem><asp:ListItem Value="3"> 经验值支付</asp:ListItem>
</asp:RadioButtonList>
我在.cs文件中有这样的要求,当用户现金不足时,
“现金支付”这个选项呈灰色,不可选,怎么实现啊
问题点数:0、回复次数:6Top
1 楼boytomato(深爱一人叫颖的女孩!)回复于 2005-06-03 21:09:49 得分 0
<%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="WebService.WebForm4" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm4</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function onload() {
var radioButton = document.getElementsByTagName("input")
for (var i=0;i<radioButton.length;i++) {
if (radioButton[i].type == "radio") {
if (radioButton[i].value=="ALFKI")
{
radioButton[i].disabled=true;
}
}
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="onload()">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:RadioButtonList id="RadioButtonList1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 216px"
runat="server" Height="56px" Width="520px"></asp:RadioButtonList></FONT>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebService
{
/// <summary>
/// WebForm4 的摘要说明。
/// </summary>
public class WebForm4 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected WebService.DataSet1 dataSet11;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
this.oleDbDataAdapter1.Fill (this.dataSet11 .Customers);
this.RadioButtonList1 .DataSource=this.dataSet11 .Customers ;
this.RadioButtonList1.DataTextField="CustomerID";
this.RadioButtonList1.DataValueField="CustomerID";
this.RadioButtonList1 .DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.dataSet11 = new WebService.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
//
// oleDbDataAdapter1
//
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"),
new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID")})});
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT CompanyName, CustomerID FROM Customers";
this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"User ID=sa;Data Source=GW;Tag with column collation when possible=False;Initial Catalog=Northwind;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=GW;Use Encryption for Data=False;Packet Size=4096";
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
}
#endregion
}
}
Top
2 楼boytomato(深爱一人叫颖的女孩!)回复于 2005-06-03 21:10:40 得分 0
function onload() {
var radioButton = document.getElementsByTagName("input")
for (var i=0;i<radioButton.length;i++) {
if (radioButton[i].type == "radio") {
if (radioButton[i].value=="ALFKI") //注意这
{
radioButton[i].disabled=true;
}
}
}
Top
3 楼wanghuirui(wanghuirui)回复于 2005-06-03 23:34:59 得分 0
upTop
4 楼wanghuirui(wanghuirui)回复于 2005-07-03 20:40:19 得分 0
upTop
5 楼wt000000(店小2£)回复于 2005-07-03 20:50:22 得分 0
if (radioButton[i].value=="ALFKI")
ALFKI是什么啊
Top
6 楼WZCNet(只有想不到,没有做不到)回复于 2005-07-03 20:51:52 得分 0
只能用JavaScript实现,实现代码楼上几位已回复,提醒注意的就是用JS设置的样式要页面第次回发时都要设置一下,因为JS的设置不会保存控件的状态Top




