ListBox的数据绑
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
getData();
}
public void getData()
{
SqlConnection con = new SqlConnection("Server=.;Database=test;Integrated Security=SSPI");
con.Open();
SqlCommand cmd = new SqlCommand("select Score from More", con);
DataSet dst = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(cmd);
dap.Fill(dst, "More");
ListBox1.DataMember = "More";//得到数据源中表的名称。。。
ListBox1.DataTextField = "Score";//在文本字段中要显示的内容在数据源中此列的名称。,。
ListBox1.DataSource = dst.Tables[0].DefaultView;//下面这两句经常在一起哟。。
ListBox1.DataBind();
con.Close();
}
}