嵌套中继器-子中继器价格选中复选框,单击父中继器价格

时间:2019-01-18 05:44:34

标签: javascript c# jquery asp.net webforms

我嵌套了中继器,父中继器具有价格,名称,描述,子中继器也具有相同的东西,但是具有不同的值,我对如何添加以下任一子标志的价格有些困惑将子中继器项目转换为客户端父中继器的价格。

我想实现这一点,就像单击“复选框”时,复选框文本应更改为“已添加”,而价格应更新。

更新

有效的我的代码:

<asp:Repeater
    ID="Repeater3"
    runat="server"
    OnItemDataBound="Repeater1_ItemDataBound">
    <ItemTemplate>
        <div class="card border-success mb-3">
            <div class="card-header bg-success text-white h4">
                <%# Eval("PName") %>
            </div>
            <div class="card-body">
                <%# Eval("PDescription") %>
                <div id="ChildRepeater" runat="server">

                    <asp:Repeater ID="Repeater2" runat="server">
                        <ItemTemplate>
                            <div class="card border-danger my-3">
                                <div class="card-body">
                                    <h4><%# Eval("PName") %></h4>
                                    <h6><asp:Label ID="lblChildPrice" runat="server" Text='<%# Eval("PRate") %>'></asp:Label></h6>
                                </div>
                                <div class="card-footer">
                                    <asp:CheckBox ID="chkAdd" Text="Add" OnCheckedChanged="chkbxAdd_CheckedChanged" runat="server" />
                                </div>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>

                </div>
            </div>
            <div class="card-footer text-muted">
                <h2><asp:Label ID="lblParentPrice" runat="server" Text='<%# Eval("PRate") %>'></asp:Label></h2>
            </div>
        </div>
    </ItemTemplate>
</asp:Repeater>

背后的代码:

protected void chkbxAdd_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk = (CheckBox)sender;
            RepeaterItem rtpritem = (RepeaterItem)chk.NamingContainer;
            Label lblPlanPrice = (Label)rtpritem.FindControl("lblChildPrice");
            Repeater rptr = (Repeater)chk.NamingContainer.Parent;
            Label lblParentPlanPrice = (Label)rptr.NamingContainer.FindControl("lblParentPrice");

            lblParentPlanPrice.Text = Convert.ToString(double.Parse(lblParentPlanPrice.Text) + double.Parse(lblPlanPrice.Text));

        }

谢谢

0 个答案:

没有答案