当选择的索引发生变化时,UpdatePanel中的Asp.Net下拉列表不会回发

时间:2016-02-16 13:49:51

标签: c# asp.net updatepanel dropdown

在我的项目中,我在updatepanel中放置了两个下拉列表。但下拉列表selectedindexchanged无效。 它是我在aspx文件中的设计代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Page.master"  AutoEventWireup="true" CodeFile="NewJob.aspx.cs" Inherits="NewJob" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="panel-body">
    <asp:ScriptManager ID="MainScriptManager" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
      <Triggers>
            <asp:AsyncPostBackTrigger ControlID="drpCategory" EventName="SelectedIndexChanged" />
      </Triggers>
      <ContentTemplate>
        <table>
          <tr class="centered">
            <td class="table-field" colspan="4">
            <br />
            </td>
          </tr>
          <tr>
            <td class="table-title">
              Category :
            </td>
            <td class="table-field">
              <asp:DropDownList ID="drpCategory" CssClass="piran-control" runat="server" Width="300px"  AutoPostBack="True" ViewStateMode="Enabled" EnableViewState="True" OnSelectedIndexChanged="drpCategory_SelectedIndexChanged">
              </asp:DropDownList>
            </td>
            <td style="padding-right:40px;" >
              SubCategory :
            </td>
            <td class="table-field" colspan="4">
              <asp:DropDownList ID="drpSubCategory" CssClass="piran-control" runat="server" Width="300px" ViewStateMode="Enabled" EnableViewState="True">
              </asp:DropDownList>
            </td>  
          </tr>         
          <tr>
            <td>
              <asp:Button ID="btnInsert" runat="server" Text=" Insert " class="submit_btn btn btn-success" OnClick="Button1_Click" ValidationGroup="Validation" />                
            </td>
          </tr> 
        </table>
      </ContentTemplate>
    </asp:UpdatePanel>
    </div>
</asp:Content>

这是我背后的代码:

protected void Page_Load(object sender, EventArgs e) {
  if (!Page.IsPostBack) {
    cData.loadCategory(myDs);
    drpCategory.DataValueField = "ID";
    drpCategory.DataTextField = "Name";
    drpCategory.DataSource = myDs.tblCategory;
    drpCategory.DataBind();     
  }
}

protected void drpCategory_SelectedIndexChanged(object sender, EventArgs e) {
  userData.catID = Int32.Parse(drpCategory.SelectedValue);
  cData.loadSubCategory(myDs);
  drpCategory.DataValueField = "ID";
  drpCategory.DataTextField = "Name";
  drpCategory.DataSource = myDs.tblSubCategory;
  drpCategory.DataBind();
}

我希望当ajax中的drpCategory回发的chande项目或索引以及drpSubCategory中的show sub类别。 你的解决方案是什么?

1 个答案:

答案 0 :(得分:0)

不要忘记在更新面板中设置AsyncPostbackTrigger

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="drpCategory" EventName="SelectedIndexChanged" />
</Triggers>