我正在尝试将文本框绑定到C#中的下拉列表。我无法绑定文本框和下拉列表。
帮我解释一下这段代码
public void BindDropDownListData()
{
String strConnString = ConfigurationManager.ConnectionStrings["sample11"].ConnectionString;
using (SqlConnection mySqlConnection = new SqlConnection(strConnString))
{
try
{
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("dbo.SCM_JOB_DISPLAY", mySqlConnection);
mySqlCommand.CommandType = CommandType.StoredProcedure;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySqlCommand);
DataSet myDataSet = new DataSet();
mySqlDataAdapter.Fill(myDataSet);
DropDownList1.DataSource = myDataSet;
DropDownList1.DataTextField = "HTTIS_Issue_Number";
DropDownList1.DataValueField = "HTTIS_Job_Code";
DropDownList1.DataBind();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
finally
{
mySqlConnection.Close();
}
}
}
答案 0 :(得分:0)
尝试绑定
myDataSet.Tables[0]
而不是整个数据集。