问题
In my application I want to create a dynamic datalist and bind the database values. please help me this is my code
protected void btn_Click(object sender, EventArgs e)
{
DataList datlst = new DataList();
da = new SqlDataAdapter("select emname from emp", con);
ds = new DataSet();
da.Fill(ds, "emp");
datlst.DataSource = ds.Tables[0];
datlst.DataBind();
//this.Controls.Add(datlst);
form1.Controls.Add(datlst);
}
回答1:
On the codeBehind file write
DtaList dl = new DataList();
dl.DataSource = //Data from DB
dl.DataBind();
来源:https://stackoverflow.com/questions/1465053/how-to-create-datalist-dynamically