<asp:dropdownlist id="DropDownList1" runat="server" datavaluefield="product_id" datatextfield="product_name" width="100px" onselectedindexchanged="SelectedindexChanged" xmlns:asp="#unknown" />
you need to bind the DataSource of your dropdownlist.
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlCommand cmd = new SqlCommand("select product_name,product_rate from product_detail", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "product_detail");
gridView1.DataSource = ds;
gridView1.DataBind();
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1");
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlCommand cmd = new SqlCommand("select product_name,product_rate from product_detail", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "product_detail");
DropDownList1.DataSource = ds.Table[0];
DropDownList1.DataTextField="product_name";
DropDownList1.DataValueField ="product_id";
DropDownList1.DataBind();
}
}
If this helped you then please Vote and mark it as answer.