无法填充下拉列表。任何人都可以提供帮助,可能是我的错误教程吗?我不知道如何填充我的数据源。对C#或ASP.Net来说很陌生,所以对我来说很容易。
protected void Button1_Click(object sender, EventArgs e)
{
List<string> _newList = new List<string>();
if (TextBox1.Text != null)
{
OdbcDataReader MapResult; //Data Reader
Database db = new Database();
string lat = "";
string sql = " SELECT
informix.dbimg_mstr_rec.doc_path
FROM
informix.dbimg_mstr_rec
WHERE
informix.dbimg_mstr_rec.doc_key
= '" + TextBox1.Text + "'";
try
{
MapResult = db.ExecQuery(sql, timeOut);
if (MapResult.Read())
{
lat = MapResult["doc_path"].ToString();
DropDown1.DataSource = _newList;
DropDown1.DataTextField = "doc_path";
DropDown1.DataValueField = "doc_path";
form1.Controls.Add(DropDown1);
} //end if
MapResult.Close();
db.CloseConnection();
//end while
}//end try
catch (OdbcException ex)
{
errList.Add("[User] Error 109: " + ex.Message);
} //end catch
return;
} //end if
else
return;
}
答案 0 :(得分:0)
看起来你实际上并没有在这段代码中的任何地方绑定下拉列表。你需要做这样的事情:
DropDown1.DataTextField = "doc_path";
DropDown1.DataValueField = "doc_path";
DropDown1.DataSource = dr.ExecuteReader();
DropDown1.DataBind();
或者,您可以使用SqlDataSource控件在页面标记中完成所有操作。
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
DataSourceMode="DataSet"
ConnectionString="myConnString"
SelectCommand="myStoredProcedure"
>
</asp:SqlDataSource>
<asp:MyDropDownList id="DropDown1" runat="server" DataSource="SqlDataSource1"
DataTextField="COLUMN_NAME" DataValueField="COLUMN_NAME" />