验证中...
Languages: ASP
Categories: Web开发技术
Latest update 2018-12-28 09:35
ListBox控件
Raw Copy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Listbox
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataSet ds = new DataSet();
ds.Tables.Add("stu");
ds.Tables["stu"].Columns.Add("stuNo", typeof(int));
ds.Tables["stu"].Columns.Add("stuName",typeof(string));
ds.Tables["stu"].Columns.Add("stuScore", typeof(int));
ds.Tables["stu"].Rows.Add(new object[] { 1, "张三", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 2, "网二", 100 });
this.ListBox1.DataSource = ds.Tables["stu"];
this.ListBox1.DataTextField = "stuName";
this.ListBox1.DataValueField = "stuNo";
this.ListBox1.DataBind();
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label1.Text = "你选择的学生是:" + ListBox1.SelectedValue.ToString() + "姓名:" + ListBox1.SelectedItem.Text.ToString();
}
}
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close