, 뒤의 코드는 다음과 같습니다 :데이터베이스에서 드롭 다운 목록을 채우는 방법? 내 드롭 다운 목록을 채우기 위해 노력하고있어 그래서 여기
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(CommonFunctions.GetAppDBConnection(Constants.AppID, Constants.TMDDBConnection));
con.Open();
SqlCommand mycommand = new SqlCommand("select * from MSUnit", con);
SqlDataReader ddlvalues = mycommand.ExecuteReader();
ddlTransactionCategory.DataSource = ddlvalues;
ddlTransactionCategory.DataTextField = "categoryCode";
ddlTransactionCategory.DataValueField = "OrgID";
ddlTransactionCategory.DataBind();
mycommand.Connection.Close();
mycommand.Connection.Dispose();
}
문제는, 내가이 일을 어떤 도움을받을 수없는 것? 이 코드가 올바르게 작동합니까?
ddlvalues는 SqlDataReader 개체입니다. 드롭 다운 컨트롤의 유효한 DataSource가 아닙니다. ddlvalues에 값을 가져 와서 적절한 컨테이너에 넣어야합니다. 일반 목록이라고하면 데이터 소스로 지정합니다. 사용 후 SqlDataReader를 삭제하십시오. – rikitikitik
그래서? 내 실수, 고마워! :) –