版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011046042/article/details/85224792
- 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
public partial class Alerm_in_alerm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataSet ds = new DataSet();
ds.Tables.Add("in");
ds.Tables["in"].Columns.Add("No",typeof(int));
ds.Tables["in"].Columns.Add("name", typeof(string));
ds.Tables["in"].Columns.Add("data", typeof(int));
ds.Tables["in"].Rows.Add(new object[]{1,"张三",200});
ds.Tables["in"].Rows.Add(new object[]{2,"张2",200});
ds.Tables["in"].Rows.Add(new object[]{3,"张a",200});
ds.Tables["in"].Rows.Add(new object[]{4,"张b",200});
ds.Tables["in"].Rows.Add(new object[]{5,"张i",200});
this.DropDownList1.DataSource = ds.Tables["in"];
this.DropDownList1.DataValueField = "No";
this.DropDownList1.DataTextField = "name";
this.DropDownList1.DataBind();
}
}
}
- 界面如下:
- 执行效果如下: