Tuesday, March 1, 2011

How to create datalist dynamically

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);
}
From stackoverflow
  • On the codeBehind file write

    DtaList dl = new DataList();
    dl.DataSource = //Data from DB 
    dl.DataBind();
    
    James McCormack : Other things to bear in mind: 1. Set the DataList's ID property e.g dl.ID = "myDataList"; 2. Add the DataList to the page/control e.g. using this.Controls.Add(dl); 3. Bind the DataList in a test for IsPostback if the query is not dynamic.
    Surya sasidhar : thank u for response but it is not getting please recheck once i send total code checkout thank u
    Surya sasidhar : mr.msi r u there please help about dynamic datalist

0 comments:

Post a Comment