📄 grouplisttest.aspx.cs
字号:
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;
using Bestcomy.Web.UI.WebControls;
namespace WebControlTest
{
/// <summary>
/// GroupListTest 的摘要说明。
/// </summary>
public class GroupListTest : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected Bestcomy.Web.UI.WebControls.GroupList Grouplist2;
protected Bestcomy.Web.UI.WebControls.GroupList Grouplist3;
protected Bestcomy.Web.UI.WebControls.GroupList GroupList1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
for(int i=1; i < 4; i++)
{
GroupItem gItem = new GroupItem("Group_"+i.ToString());
for(int j=1; j < 6; j++)
{
GroupListItem item = new GroupListItem(gItem.Label + "_Item_" + j.ToString());
gItem.Items.Add(item);
}
GroupList1.GroupItems.Add(gItem);
}
DataTable dt = new DataTable();
dt.Columns.Add("group", typeof(string));
dt.Columns.Add("text", typeof(string));
dt.Columns.Add("value", typeof(string));
for(int i=0; i < 10; i++)
{
DataRow ndr = dt.NewRow();
ndr["group"] = "Group_" + ((int)(i%2)+1).ToString();
ndr["text"] = "Text_" + ((int)(i+1)).ToString();
ndr["value"] = "value_" + ((int)(i+1)).ToString();
dt.Rows.Add(ndr);
}
this.Grouplist2.DataGroupField = "group";
this.Grouplist2.DataTextField = "text";
this.Grouplist2.DataValueField = "value";
this.Grouplist2.DataSource = dt.DefaultView;
this.Grouplist2.DataBind();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.GroupList1.SelectedIndexChanged += new System.EventHandler(this.GroupList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void GroupList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Response.Write(this.GroupList1.SelectedItem.Value);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -