Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii i have a DDL in gridview coloumn.
and a table in database named product_size where size values are inserted(5pc,10pc,15pc)
in gridview i want to Bind this ddl from database inside gridview...and populate this.
Plzz help me i tried a lot bt nt success...!!


Posted
Comments
[no name] 6-Feb-14 6:49am    
use rowdatabound event to bind the datasource to your DDL from database.

Refer this code it will help you..
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow && gvProduct.EditIndex == e.Row.RowIndex)
    {
        DropDownList product_size= (DropDownList)e.Row.FindControl("ddlproduct_size");
        string query = "select distinct product_size from product";
        SqlCommand cmd = new SqlCommand(query);
        ddlCities.DataSource = GetData(cmd);
        ddlCities.DataTextField = "product_size";
        ddlCities.DataValueField = "product_size";
        ddlCities.DataBind();
        ddlCities.Items.FindByValue((e.Row.FindControl("lblproduct_size") as Label).Text).Selected = true;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900