我有2個下拉列表(ddl1,ddl2)和一個帶有2個下拉列表(gddl1,gddl2)的gridview。在SelectedIndexChanged
ddl1事件正在更改gddl1的SelectedIndex
回發。Dropdownlist在回發中的選定值
我的問題是 ddl1.databind()發生在按鈕的單擊事件。因此,一旦ddl1的selectedIndex發生變化,所選值將丟失並返回初始值。
我不能使用!IsPostback
,因爲我在按鈕單擊時綁定ddl1。 如何保留ddl1和ddl2選定的索引。
protected void btnProceed_Click(object sender, EventArgs e)
{
if(ddlLocation.SelectedIndex > -1) {
empDS = ws_service.GetEmpList(ddlLocation.SelectedValue, ((ddlDept.SelectedValue == "All") ? "" : ddlDept.SelectedValue), ((ddlGrade.SelectedValue == "All") ? "" : ddlGrade.SelectedValue));
appraiserDS = ws_service.GetAppList();
grdDetails.DataSource = empDS.Tables[ 0 ].DefaultView;
grdDetails.DataBind();
ddlAppraiserAll.DataSource = appraiserDS.Tables[ 0 ].DefaultView;
ddlAppraiserAll.DataTextField = "APPRAISER_NAME";
ddlAppraiserAll.DataValueField = "APPRAISER_ID";
ddlAppraiserAll.DataBind();
}
}
protected void ddlAppraiserAll_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(GridViewRow gvRow in grdDetails.Rows) {
Control ctrl = gvRow.FindControl("ddlAppraiserId");
DropDownList ddl = ctrl as DropDownList;
if(ddl != null)
ddl.SelectedIndex = ddlAppraiserAll.SelectedIndex;
}
}
向我們顯示您的代碼。 – 2012-02-17 11:12:24
我已更新我的代碼。 – itzArun 2012-02-17 11:21:34
@ itzArun:嘗試使用更新面板與異步回發 – Rocky 2012-02-17 12:12:46