我在一個網頁中有兩個Dropdownlist。第二個依賴於第一個加載。例如,如果第一個是「墨爾本」,則第二個列出墨爾本的所有郊區。在PageLoad上填充兩個Dropdownlist
代碼是完美的工作,但是當我第一次加載頁面時,第二個dropdownlist2不會填充。 我需要再次選擇「墨爾本」以填充第二個下拉列表。
這裏是我的頁面加載
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["Username"] == null)
{
Response.Redirect("LoginPage.aspx");
}
if (getAccess(Session["Username"].ToString()) == false)
{
Response.Redirect("Unauthorized.aspx");
}
DataSet ds = GetAllCategory();
if (ds.Tables.Count > 0)
{
DropDownList1.DataTextField = "identifier";
DropDownList1.DataValueField = "OS_ID"; //Change field to one you want.
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataBind();
}
}
}
代碼這裏是選定的索引更改代碼
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = softwareType(Convert.ToInt32(DropDownList1.SelectedValue));
if (ds.Tables.Count > 0)
{
DropDownList2.DataTextField = "identifier";
DropDownList2.DataValueField = "ST_ID"; //Change field to one you want.
DropDownList2.DataSource = ds.Tables[0];
DropDownList2.DataBind();
}
}
我不知道如何解決這個簡單的問題?
是否已經設置的AutoPostBack = 1中真正下拉??? – Anuj
我已經完成了.. –
你想在第二個下拉列表中填充哪個事件? – Anuj