在中继器中抓取正确的 control/update 面板问题

Issue grabbing correct control/update panel in repeater

当下拉列表控件位于中继器内时,我在动态更新下拉列表控件时遇到问题。

基本上我有一个转发器,转发器里面有 2 个下拉列表。一个列表在我的 aspx 页面中定义,另一个下拉列表在更新面板内,我希望能够根据第一个下拉列表的选择动态更新它。我认为我的部分问题是更新面板变得混乱,因为我有不止一个中继器项目?

这是我的中继器的代码:

<asp:Repeater ID="billingTemplate" runat="server" OnItemDataBound="template_ItemDataBound">
    <ItemTemplate>
        <tr style="font-size: 100%" runat="server">
            <td colspan="4" style="width: 100%; vertical-align: top">
                <div class="panel panel-default panel-billing">
                    <asp:Panel CssClass="row panel-heading panel-heading-billing text-left" ID="headingBilling" ClientIDMode="Static" runat="server">
                        <div class="col-xs-1">
                            <input type="hidden" id="templateUK" runat="server" value='<%#Eval("templateUK")%>' />
                            <a href="#collapseBilling" id="BillingPanelBtn" clientidmode="Static" class="btn btn-block btn-group-xs panel-button glyphicon glyphicon-chevron-down" data-toggle="collapse" runat="server"></a>
                        </div>
                        <div class="col-sm-3">
                            <label for="ddlInvFilterType" class="col-sm-4 control-label text-right labelCls testclass">Filter Type:</label>
                            <div class="col-sm-8">
                                <asp:DropDownList runat="server" ID="ddlInvFilterType" ClientIDMode="Static" placeholder="Choose Filter Type" CssClass="form-control smallSize FilterType" AutoPostBack="true" OnSelectedIndexChanged="ddlFilterType_SelectedIndexChanged">
                                    <asp:ListItem Value="">- None -</asp:ListItem>
                                    <asp:ListItem Value="RevType1">Revenue Type 1</asp:ListItem>
                                    <asp:ListItem Value="RevType2">Revenue Type 2</asp:ListItem>
                                    <asp:ListItem Value="RevType3">Revenue Type 3</asp:ListItem>
                                    <asp:ListItem Value="ServiceTeams">Service Team</asp:ListItem>
                                </asp:DropDownList>
                            </div>
                        </div>
                        <asp:UpdatePanel ID="InvFilterValuePanel" ClientIDMode="Static" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
                            <ContentTemplate>
                                <div class="col-sm-3">
                                    <label for="ddlInvFilterValue" class="col-sm-4 control-label text-right labelCls">Filter Value:</label>
                                        <div class="col-sm-8">
                                            <asp:DropDownList runat="server" ID="ddlInvFilterValue" ClientIDMode="Static" placeholder="Choose Filter Value" CssClass="col-sm-6 form-control smallSize">
                                                <asp:ListItem Value="">- None -</asp:ListItem>
                                            </asp:DropDownList>
                                        </div>
                                </div>
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="ddlInvFilterType" EventName="SelectedIndexChanged" />
                            </Triggers>
                        </asp:UpdatePanel>
                    </asp:Panel>
                    <asp:Panel CssClass="panel-collapse collapse" ID="collapseBilling" ClientIDMode="Static" runat="server">
                        <div class="panel-body">
                            <table class="table table-condensed table-bordered" style="margin: 0; padding: 0; border-top: none; border-bottom: none; border-left: thin; border-right: thin">
                                <tbody>                                                                
                                    <%-- other controls --%>
                                </tbody>
                            </table>
                        </div>
                    </asp:Panel>
                </div>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

这是我选择的索引更改的代码:

protected void ddlFilterType_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        DropDownList ddl = (DropDownList)sender;

        string ddlClass = ddl.CssClass;
        string[] classes = ddlClass.Split(' ');
        string repeaterClass = classes[classes.Length - 1];
        string repeaterID = "0";

        string appendStr = "";

        if (repeaterClass.Contains("templateID"))
        {
            repeaterID = repeaterClass.Substring(repeaterClass.Length - 1);
            appendStr = "_" + repeaterID;
        }            

        foreach (RepeaterItem item in billingTemplate.Items)
        {
            HtmlInputHidden hidden = item.FindControl("headingBilling").FindControl("templateUK") as HtmlInputHidden;

            if (hidden.Value == repeaterID)
            {
                DropDownList d1 = item.FindControl("headingBilling").FindControl("ddlInvFilterType") as DropDownList;
                DropDownList d2 = item.FindControl("headingBilling").FindControl("ddlInvFilterValue") as DropDownList;

            if (d1.SelectedValue.Length > 0)
            {
                d2.Items.Clear();
                d2.Items.Add(new ListItem(" - None - ", ""));
                    switch (d1.SelectedValue)
                    {
                        case "ServiceTeams":
                            foreach (var pair in serviceTeamsController.GetAllServiceTeamsLOVs())
                            {
                                if (!String.IsNullOrWhiteSpace(pair.Value))
                                    d2.Items.Add(new ListItem(pair.Value, pair.Key));
                            }
                            break;
                        default:
                            foreach (var pair in masterController.GetMasterLOVs(filterTypeDict[d1.SelectedValue]))
                            {
                                if (!String.IsNullOrWhiteSpace(pair.Value))
                                {
                                    d2.Items.Add(new ListItem(pair.Value, pair.Key));
                                }
                            }
                            break;                                
                        }
                    }
                    else
                    {
                        d2.Items.Clear();
                        d2.Items.Add(new ListItem(" - None - ", ""));
                    }                   
            }                
        }
    }
    catch (Exception ex)
    {

    }
}

这是我在有多个中继器项目时查看的屏幕截图:

基本上现在发生的事情是,如果我更新项目 2 中的过滤器类型,它将更新项目 1 中的过滤器值。如果我更新项目 1 中的过滤器类型,它将按预期更新项目 1 中的过滤器值。

我想要的是能够更新 item2 过滤器类型,然后相应地更新 item 2 中的过滤器值。

有人知道我可能遗漏了什么吗?

所以最终让它起作用了,我认为主要问题是 clientidmode 以某种方式混淆了更新面板,所以我删除了它并使更新面板绕过两个下拉菜单。我也没有最终需要触发器,所以我也删除了它。