繁体   English   中英

所选索引更改时,UpdatePanel中的Asp.Net Dropdownlist不回发

[英]Asp.Net Dropdownlist in UpdatePanel Doesn't Postback When Selected Index Changed

在我的项目中,我在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回发的项目或索引时,并在drpSubCategory中显示子类别。 你有什么解决方案?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM