Hi
I have below data . In Dropdown it is showing System.Data.DataRowView
private void GetLocation()
{
try
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["cnn_Live"].ConnectionString; ;
SqlCommand cmd = new SqlCommand("select docentry,locationname from Location", con);
cmd.CommandType = CommandType.Text;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
ddlLocation.DataSource = dt;
ddlLocation.DataBind();
con.Close();
}
}
catch (Exception ex)
{
ShowMessage("", ex.Message, "error");
}
}
Thanks
Tahir AnsariPosted Sep 1, 2024, 11:55 AM
Hi Ramco,
Dropdown list is displaying "System.Data.DataRowView" instead of the actual values, typically occurs when the DataTextField property of the dropdown list is not set. This property tells the dropdown list which column from the data source to display.
You can fix it by following way,
Set the DataTextField to the column name you want to display (in your case, locationname).
Optionally, set the DataValueField to another column, like docentry, if you need a value associated with each item
The dropdown list (ddlLocation) will now display the locationname values.
Each item in the dropdown will have a value corresponding to the docentry