I am populating dropdown into gridview.when i am running application, in dropdown it shows me this data System.Data.Datarawview.
Here I have pasted my code :
public void FindControlInGV()
{
foreach (GridViewRow gvr in gvPopulate.Rows)
{
SqlDataAdapter ad = new SqlDataAdapter("select B_Element from Test_Table", con);
DataSet ds = new DataSet();
ad.Fill(ds, "Test_Table");
DropDownList ddlSelect = new DropDownList();
ddlSelect = (DropDownList)gvr.Cells[0].FindControl("ddlPopulate");
ddlSelect.DataSource = ds;
ddlSelect.DataBind();
}
//}
}
I am new to asp.net pls help me out.


Suthish NairRank #92 · 22.8K reputationPosted Jul 1, 2011, 4:14 AM EDT
ddlSelect.DataSource = ds.Tables(0)
ddlSelect.DataTextField = "Column name to de displayed to user"
ddlSelect.DataValueField = "Column name for your logic"
ddlSelect.DataBind()
Sandeep ShekhawatRank #2,439 · 577 reputationPosted Jul 1, 2011, 4:15 AM EDT
}
use this this symptoms comes for dropdown list that have no value and text filed.
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jul 1, 2011, 4:17 AM EDT
public void FillDropDownList()
{
s = WebConfigurationManager.ConnectionStrings["ChartDatabaseConnectionString"].ConnectionString;
con = new SqlConnection(s);
con.Open();
cmd = new SqlCommand("Select StudentName from Student", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
otherwise...
i think mistake is locates here
ddlSelect = (DropDownList)gvr.Cells[0].FindControl("ddlPopulate");
Sahil Jani196 reputationPosted Jul 1, 2011, 4:26 AM EDT