本文介绍了从Excel列填充DropDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试从excel列中填充下拉列表.
一切都很好,但是它显示的是system.data.datarow而不是下拉列表中的值".

以下代码中wat的错误.

Hi,

I am trying to fill dropdown from excel column.
Every thing was fine ,but it''s displaying system.data.datarow instead of Values in dropdown list.

wat''s the mistake in the following code.

           DataTable dt = new DataTable();
          string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\OnCall Tracker_2011.xls;Extended Properties='Excel 8.0;HDR=NO'";
            using (OleDbConnection conn = new OleDbConnection(connString))
            {
                conn.Open();
                //Where [F1] = column one, [F2] = column two etc, etc.              
                //OleDbCommand objCmdSelect = new OleDbCommand(sqlQuery, conn);                   
                //objCmdSelect.ExecuteNonQuery();
                string sqlQuery = "select distinct [F1] AS [id] from [July -11$]";
                OleDbDataAdapter adapter = new OleDbDataAdapter(sqlQuery, conn);
                adapter.Fill(dt);
            DropDownList1.DataSource = dt;
            DropDownList1.DataBind();
}



在此先感谢
Subhash G



Thanks In Advance
Subhash G

推荐答案



在此先感谢
Subhash G



Thanks In Advance
Subhash G


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


DropDownList1.DataTextField= dt.Columns[0].ToString();
DropDownList1.DataValueField = dt.Columns[0].ToString();


这篇关于从Excel列填充DropDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 22:52
查看更多