none
Populate dropdownlist inside a gridview RRS feed

  • Question

  • I have a Dropdownlist in a Gridview and i have to show the firstname as a label and corresponding lastname in  a DDL. how can i show them??Any help can be appreciated.
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    con.Open();
                    var ddl = (DropDownList)e.Row.FindControl("DropDownList1");
                    //int CountryId = Convert.ToInt32(e.Row.Cells[0].Text);
                    SqlCommand cmd = new SqlCommand("select LastName from Profile_Master",        con);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    con.Close();
                    ddl.DataSource = ds;
                    ddl.DataTextField = "LastName";
                    ddl.DataBind();
    
                }
            }
    

    • Moved by Mike Dos Zhang Thursday, November 1, 2012 9:24 AM (From:Visual C# General)
    Wednesday, October 24, 2012 11:35 AM

All replies