DropDownList实例中的System.Data.DataRowView实际值

时间:2016-12-14 07:42:10

标签: asp.net

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();
}

我在实际值的下拉列表实例中获取system.data.datarowview

1 个答案:

答案 0 :(得分:1)

您未指定DataTextFieldDataValueField属性。这些应该是DataTable中列的名称。

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