簡體   English   中英

dropdownlists selectedIndexchanged事件不會被觸發

[英]Dropdownlists selectedIndexchanged event does not get fired

我的頁面在updatepanel的頁面和一個按鈕上包含四個下拉列表。我將數據綁定到Page_Load事件上的所有下拉列表,並且當我從任何一個下拉列表中選擇項目時,它們各自的selectedindexchanged事件根本不會被觸發。所有下拉列表的Autopostback屬性都設置為true。這使page_load事件可以調用,但不會觸發selectedindexchanged事件。

<asp:UpdatePanel ID="UpdatePanelDialysisMachine" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
              <table id="tableDialysisMachine" runat="server" clientidmode="Static" style="width: 98%;
                display: table; margin-left: 10px; margin-right: 5px" border="0" cellpadding="2"
                cellspacing="2" class="table">
                <tr>
                    <th style="height: 10px; width: 100%">
                    </th>
                </tr>
                <tr>
                    <td style="height: 10px; width: 100%;" align="center">
                         <asp:Label ID="LabelDialysisSession" runat="server" Text="Dialysis Session" CssClass="sectionHeader"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <th style="height: 10px; width: 100%">
                    </th>
                </tr>
                <tr>
                    <td style="width: 100%" align="center"><asp:Label ID="LabelMachineMessage" runat="server" Visible="false" ClientIDMode="Static"></asp:Label>
                    </td>
                </tr>                    
                <tr>
                    <td>
                    <fieldset>
                        <legend>
                           <asp:Label ID="LabelSelectMachines" runat="server" Text="Dialysis Machine"></asp:Label>
                        </legend>

                   <%-- </td>
                </tr>
                <tr>
                    <th style="height: 10px">
                    </th>
                </tr>

                <tr>
                    <td>--%>
                        <table style="width: 100%;"  border="0" cellpadding="2" cellspacing="2">
                           <tr>
                                <th colspan="2" style="height: 10px">
                                </th>
                            </tr>
                            <tr>
                                <td class="textRightAlign" style="width: 50%">
                                    <asp:Label ID="LabelMachine" runat="server" Text="Select Machine"></asp:Label>
                                </td>
                                <td class="textLeftAlign" style="width: 50%">
                                    &nbsp;&nbsp;<asp:DropDownList ID="DropdownMachinesList" runat="server" 
                                        CssClass="dropDown" EnableViewState="true" 
                                        onselectedindexchanged="DropdownMachinesList_SelectedIndexChanged" 
                                        AutoPostBack="True" >
                                    </asp:DropDownList>
                                </td>
                            </tr>
                             <tr>
                                <th style="height: 10px" colspan="2">
                                </th>
                            </tr>
                        </table>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                <td>
                <fieldset>
                <legend>
                <asp:Label ID="LabelAssignStaff" runat="server" Text="Assign Staff"></asp:Label>
                </legend>
                <table style="width: 100%;"  border="0" cellpadding="2" cellspacing="2">
                           <tr>
                                <th colspan="2" style="height: 10px">
                                </th>
                            </tr>
                              <tr>
                <td class="textRightAlign">
                    <asp:Label ID="LabelPrimaryDoctor" runat="server" Text="Primary Doctor" EnableViewState="true" ></asp:Label>
                </td>
                <td class="textLeftAlign">
                    <asp:DropDownList ID="DropDownListPrimaryDoctor" runat="server" 
                        ClientIDMode="Static" CssClass="dropDown" EnableViewState="true" 
                        AutoPostBack="True">

                    </asp:DropDownList>
                </td>
                <td class="textRightAlign">
                    <asp:Label ID="LabelSecondaryDoctor" runat="server" Text="Secondary Doctor"></asp:Label>
                </td>
                <td class="textLeftAlign">
                    <asp:DropDownList ID="DropDownListSecondaryDoctor" runat="server" ClientIDMode="Static" CssClass="dropDown" EnableViewState="true">

                    </asp:DropDownList>
                </td>
           </tr>
            <tr>
                <td class="textRightAlign">
                    <asp:Label ID="LabelPrimaryNurse" runat="server" Text="Primary Nurse"  ></asp:Label>
                </td>
                <td class="textLeftAlign" width="20px">
                    <asp:DropDownList ID="DropDownListPrimaryNurse" runat="server" ClientIDMode="Static" CssClass="dropDown" EnableViewState="true">


                    </asp:DropDownList>
                </td>
                <td class="textRightAlign">
                    <asp:Label ID="LabelSecondaryNurse" runat="server" Text="Secondary Nurse" meta:resourcekey="LabelSecondaryNurseResource1"></asp:Label>
                </td>
                <td class="textLeftAlign" width="20px">
                    <asp:DropDownList ID="DropDownListSecondaryNurse" runat="server" ClientIDMode="Static" CssClass="dropDown" EnableViewState="true">

                    </asp:DropDownList>
                </td>
            </tr>
                             <tr>
                                <th style="height: 10px" colspan="2">
                                </th>
                            </tr>

                        </table>
                </fieldset>
                </td>
                </tr>
                <tr>
                            <td style="width:100%" align="center">
                                <asp:Button ID="buttonCreateSession" runat="server" CssClass="buttonExpanded" 
                                    Text="Create Session" ClientIDMode="Static" CausesValidation="false" 
                                    onclick="buttonCreateSession_Click" /></td>
                            </tr>
                             <tr>
                                <th style="height: 10px">
                                </th>
                            </tr>
            </table>
        </ContentTemplate>

    </asp:UpdatePanel>

這是背后的代碼;

 protected void Page_Load(object sender, EventArgs e)
{

    if (Page.IsPostBack == false)
    {          
        GetDoctors();
        GetNurse();
        GetMachines();
    }        


} 

 private void GetMachines()
{
    DataTable machines = null;
    try
    {
        machines = m_DialysisSessionManager.GetInactiveMachines();
        if (machines != null)
        {
            //ListItem l8 = new ListItem();
            //l8.Text = "-Select-";
            //l8.Value = "-1";
            //l8.Selected = true;
            //DropDownListmachine.Items.Add(l8);
            DropdownMachinesList.DataSource = machines;
            DropdownMachinesList.DataTextField = "SerialNumber";
            DropdownMachinesList.DataValueField = "id";
            DropdownMachinesList.DataBind();
            DropdownMachinesList.Items.Insert(0, new ListItem("-Select-"));

        }
    }
    catch (Exception ex)
    {
        LoggingHelper.WriteError(ex);
    }
}

/// <summary>
/// Gets doctors list
/// </summary>
private void GetDoctors()
{
    DataTable doctors = null;
    try
    {
        doctors = m_DialysisSessionManager.GetDoctorsList();
        if (doctors != null)
        {

            DropDownListPrimaryDoctor.DataSource = doctors;
            DropDownListPrimaryDoctor.DataTextField = "Name";
            DropDownListPrimaryDoctor.DataValueField = "UserId";
            DropDownListPrimaryDoctor.DataBind();
            DropDownListPrimaryDoctor.Items.Insert(0, new ListItem("-Select-"));


            DropDownListSecondaryDoctor.DataSource = doctors;
            DropDownListSecondaryDoctor.DataTextField = "Name";
            DropDownListSecondaryDoctor.DataValueField = "UserId";
            DropDownListSecondaryDoctor.DataBind();
            DropDownListSecondaryDoctor.Items.Insert(0, new ListItem("-Select-"));
        }
    }
    catch (Exception ex)
    {
        LoggingHelper.WriteError(ex);
    }
}

/// <summary>
/// Gets Nurse list
/// </summary>
private void GetNurse()
{
    DataTable nurse = null;
    try
    {
        nurse = m_DialysisSessionManager.GetNurseList();
        if (nurse != null)
        {


            DropDownListPrimaryNurse.DataSource = nurse;
            DropDownListPrimaryNurse.DataTextField = "Name";
            DropDownListPrimaryNurse.DataValueField = "UserId";
            DropDownListPrimaryNurse.DataBind();
            DropDownListPrimaryNurse.Items.Insert(0, new ListItem("-Select-"));


            DropDownListSecondaryNurse.DataSource = nurse;
            DropDownListSecondaryNurse.DataTextField = "Name";
            DropDownListSecondaryNurse.DataValueField = "UserId";
            DropDownListSecondaryNurse.DataBind();
            DropDownListSecondaryNurse.Items.Insert(0, new ListItem("-Select-"));
        }
    }
    catch (Exception ex)
    {

    }
}
 protected void DropdownMachinesList_SelectedIndexChanged(Object sender, EventArgs e)
{
    Session["machineId"] = DropdownMachinesList.SelectedItem.Text;
}

嘗試在Page OnInit事件上添加事件處理程序

DropdownMachinesList.SelectedIndexChanged += 
                   new EventHandler(DropdownMachinesList_SelectedIndexChanged);

嘗試將UpdateMode更改為Always。

如果UpdateMode屬性設置為Conditional,則需要顯式調用UpdatePanel控件的Update方法。

回發是由使用UpdatePanel控件的Triggers屬性定義為觸發器的控件引起的。

您總是可以在標記中設置事件處理程序和AutoPostBack屬性。 您已經為DropdownMachinesList完成了此操作,因此可以對其他模式遵循相同的模式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM