繁体   English   中英

在转发器中获取正确的控制/更新面板问题

[英]Issue grabbing correct control/update panel in repeater

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

基本上,我有一个中继器,在该中继器中有2个下拉列表。 一个列表在我的aspx页面中定义,另一个下拉列表在更新面板中,我希望能够根据第一个下拉列表的选择动态地对其进行更新。 我认为我的问题的一部分是updatepanel变得困惑,因为我有多个转发器项目吗?

这是我的中继器的代码:

<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)
    {

    }
}

这是当有多个转发器项目时我正在查看的屏幕截图:

在此处输入图片说明

基本上,现在发生的是,如果我更新了item2中的过滤器类型,它将更新项目1中的过滤器值。如果我更新了item1中的过滤器类型,它将按预期的那样更新项目1中的过滤器值。

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

有人对我可能会缺少的东西有什么想法吗?

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

暂无
暂无

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

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