[英]Why my Drop down list is not getting binded upon button click?
我試圖在單擊按鈕時重新綁定我的下拉菜單,特別是如果“阻止”但沒有重新綁定,我的意思是它應該重新加載下拉菜單,有點刷新,並且應該選擇第一項,我正在這樣做但沒有重新綁定
代碼:(在buttong click事件中)
if (NotAssignedConductors.Length > 0)
{
string[] NotAssignedConductorsArray = NotAssignedConductors.Split(':');
foreach (string str in NotAssignedConductorsArray)
{
ResultLabel.ResultLabelAttributes(str, ProjectUserControls.Enums.ResultLabel_Color.Red);
}
FillDropDownListDevices();
}
方法被調用:
public void FillDropDownListDevices()
{
DropDownListDevices.DataSource = ManageTransport.ManageConductorDevices.GetDevices();
DropDownListDevices.DataTextField = "TerminalSNO";
DropDownListDevices.DataValueField = "DeviceID";
DropDownListDevices.DataBind();
DropDownListDevices.Items.Insert(0, new ListItem("None", "-1"));
}
按鍵:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownListDevices" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownListDevices_SelectedIndexChanged" CssClass="form-control">
</asp:DropDownList>
<ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCreate" EventName="click" />
</Triggers>
</asp:updatePanel>
有很多可能性
如果您使用的是更新面板,請確保在單擊按鈕時觸發更新面板以進行更新
檢查您的page_load / page_loadComplete事件,並確保您不再綁定下拉菜單。
在更新面板上創建回發觸發器
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownListDevices" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownListDevices_SelectedIndexChanged" CssClass="form-control">
</asp:DropDownList>
<ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:updatePanel>
將您的第一次綁定方法放回
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//means no postback..page loaded first time
// Put your first time Binding method here
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.