내 프로젝트에서 C# 및 asp.net을 사용하고 있습니다. 드롭 다운 목록의 selectedindex를 가져오고 싶지만 항상 0으로 표시됩니다. 여기에 드롭 다운 목록을 바인딩하는 코드가 있습니다.드롭 다운 목록의 선택된 색인
보호 무효를 Page_Load (개체를 보낸 사람, EventArgs입니다 전자): 여기
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
catID = DropDownList1.SelectedIndex+1;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
techID = DropDownList2.SelectedIndex;
}
내를 Page_Load입니다 : 데이터
MySqlDataReader dr = null;
try
{
//////////////Opening the connection///////////////
mycon.Open();
string str = "select category from lk_category";
MySqlCommand command = mycon.CreateCommand();
command.CommandText = str;
dr = command.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataValueField = "category";
DropDownList1.DataBind();
dr.Close();
str = "select technology from lk_technology";
command.CommandText = str;
dr = command.ExecuteReader();
DropDownList2.DataSource = dr;
DropDownList2.DataValueField = "technology";
DropDownList2.DataBind();
}
catch (Exception ex) { Response.Write("Exception reding data" + ex); }
finally
{
//dr.Close();
mycon.Close();
}
내가 노력하고 있어요에 의해 인덱스를 선택하세요{
if (Session["valid"] == null)
Response.Redirect("admin.aspx");
panel1();///If session valid then show panel1;
}
내가 잘못 가고 곳을 가르쳐주세요.
'Page_Load' 메소드 코드를 게시 할 수 있습니까? – Eranga
@ Eranga 질문에 page_load를 추가했습니다. –