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
答案 0 :(得分:1)
您未指定DataTextField
和DataValueField
属性。这些应该是DataTable中列的名称。
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "Column1";
DropDownList1.DataValueField = "Column2";
DropDownList1.DataBind();