复制代码 代码如下:
public void Page_Load(Object src.EventArgs e)
{
ArrayList arrValue = new ArrayList();
arrValue.add("kk");
arrValue.add("dd");
arrValue.add("aa");
arrValue.add("cc");
//将数组绑定到DropDownList控件的DataSource属性
ddl.DataSource = arrValue;
ddl.DataBind();
}
复制代码 代码如下:
public void Page_Load(Object src.EventArgs e)
{
ddl.Items.Add(new ListItem("text","value");
ddl.Items.Add(new ListItem("text1","value1");
ddl.Items.Add(new ListItem("text2","value2");
}
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string myconnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+"..//database//db.mdb";
OleDbConnnection myconn=new OleDbConnnection(myconnstr);
string sqlstr="select * from test";
OleDbCommand myComm = new OleDbCommand(sqlstr,myconn);
myComm.Connection.Open();
OleDbDataReader dr=myComm.ExecuteReader();
while (dr.Read())
{
bj.Items.Add(new ListItem(dr["bjmc"].ToString(), dr["id"].ToString()));//增加Item
//或者这样也能绑定,
//DropDownList1.Items.Add( new ListItem( myReader[1].ToString(),myReader[0].ToString() ) );//增加Item
//都是要在知道Sql语句或者数据表结构的前提下才能这样绑定
}
dr.Close();
}
}
复制代码 代码如下:
SqlConnection sqlconn = new SqlConnection();
sqlconn.ConnectionString = "workstation id=localhost;packet size=4096;user
id=sa;data source=db1;persist security info=False;initial catalog=DB";
sqlconn.Open();
SqlDataAdapter sqldar = new SqlDataAdapter("select UserName from forums_Users",sqlconn);
sqldar.SelectCommand.CommandType = CommandType.Text;
DataSet Ds= new DataSet();
sqldar.Fill(Ds,"Users");
ddl.DataSource = Ds.Tables["Users"].DefaultView;
ddl.DataTextField="UsersName";
ddl.DataBind();
sqlconn.Close();
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string myconnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+"..//database//db.mdb";
OleDbConnnection myconn=new OleDbConnnection(myconnstr);
string sqlstr="select * from test";
OleDbCommand myComm = new OleDbCommand(sqlstr,myconn);
myComm.Connection.Open();
OleDbDataReader dr=myComm.ExecuteReader();
ddl.DataSource = dr;
ddl.DataBind(); 绑定倒DD1中
}
}
复制代码 代码如下:
DataBinder.eval_r(Container.DataItem,"表字段")
新闻热点
疑难解答
图片精选