Populating the DropDownList inside the FormView Control

FormView control is a template control and hence it allows other controls to be embedded inside it. You can also place a DropDownList control inside the FormView control. The code below populates the DropDownList control which is placed inside the FormView control.

private void BindData()
    {
        SqlConnection myConnection = 
new SqlConnection(ConnectionString);
        SqlDataAdapter ad = 
new SqlDataAdapter("SELECT * FROM Users", myConnection);
        DataSet ds = 
new DataSet();
        ad.Fill(ds);
        fv1.DataSource = ds;
        fv1.DataBind(); 

        FormViewRow row = fv1.Row; 

        
// Populating the DropDownList Control inside the FormView control 
        
DropDownList ddlList  = (DropDownList) row.FindControl("ddlNames");
        ddlList.DataSource = GetNames();
        ddlList.DataTextField = "FirstName";
        ddlList.DataValueField = "UserID";

        ddlList.DataBind(); 

        

    }

powered by IMHO 1.3

Print | posted @ Monday, May 22, 2006 10:18 PM

Twitter