复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for HeavenlyStem
/// </summary>
public class HeavenlyStem
{
private int _ID;
private string _Name;
public int ID
{
get { return _ID; }
set { _ID = value; }
}
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public HeavenlyStem()
{
//
// TODO: Add constructor logic here
//
}
public HeavenlyStem(int id, string name)
{
this.ID = id;
this._Name = name;
}
}
复制代码 代码如下:
private List<HeavenlyStem> GetHeavenStem()
{
List<HeavenlyStem> ListHS = new List<HeavenlyStem>();
HeavenlyStem hs = new HeavenlyStem();
hs.ID = 1;
hs.Name = "甲";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 2;
hs.Name = "乙";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 3;
hs.Name = "丙";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 4;
hs.Name = "丁";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 5;
hs.Name = "戊";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 6;
hs.Name = "己";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 7;
hs.Name = "庚";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 8;
hs.Name = "辛";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 9;
hs.Name = "壬";
ListHS.Add(hs);
hs = new HeavenlyStem();
hs.ID = 10;
hs.Name = "癸";
ListHS.Add(hs);
return ListHS;
}
复制代码 代码如下:
<asp:ListBox runat="server" SelectionMode="Multiple"></asp:ListBox>
<asp:CustomValidator runat="server" Display="None" ErrorMessage="必须选择选项" ClientValidationFunction="ValidateListBox"></asp:CustomValidator>
<asp:ValidationSummary runat="server" EnableClientScript="true"
ShowMessageBox="true" ShowSummary="false" />
<asp:Button runat="server" Text="Submit" />
复制代码 代码如下:
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Data_Binding();
}
private void Data_Binding()
{
this.ListBoxHeavenlyStem.DataSource = GetHeavenStem();
this.ListBoxHeavenlyStem.DataTextField = "Name";
this.ListBoxHeavenlyStem.DataValueField = "ID";
this.ListBoxHeavenlyStem.DataBind();
}
}
复制代码 代码如下:
function ValidateListBox(sender, args) {
var lb = document.getElementById("<%=ListBoxHeavenlyStem.ClientID%>")
var options = lb.options;
args.IsValid = false;
for (var i = 0; i < options.length; i++) {
if (options[i].selected == true) {
args.IsValid = true;
return;
}
}
}
新闻热点
疑难解答
图片精选