mudragaddamanikanta
mudragaddamanikanta

Reputation: 1

System.Data.DataRowView in DropDownList instance of actual value

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["statesid"].ConnectionString);

public DataTable bindstate()
{
    con.Open();
    SqlCommand cmd = new SqlCommand("bindstateid",con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    con.Close();
    return dt;
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        bindstateid();
    }
}

public void bindstateid()
{
    dal ds = new dal();
    DataTable dt = new DataTable();
    dt = ds.bindstate();

    DropDownList1.DataSource = dt;
    DropDownList1.DataBind();
    GridView1.DataSource = dt;
    GridView1.DataBind();
}

I am getting system.data.datarowview in the dropdownlist instance of the actual value

Upvotes: 0

Views: 433

Answers (1)

VDWWD
VDWWD

Reputation: 35564

You do not specify the DataTextField and DataValueField properties. These should be the names of a column in the DataTable.

DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "Column1";
DropDownList1.DataValueField = "Column2";
DropDownList1.DataBind();

Upvotes: 1

Related Questions