Repeater Item找不到NamingContainer

时间:2016-03-16 21:48:05

标签: c# repeater naming-containers

我最近在我的转发器中将ComboBox切换为SuggestComboBox(找到:here),因为它是包含搜索而不是启动搜索。以前,我使用ComboBox的NamingContainer来查找附近的元素。我的新SuggestComboBox没有这个价值,但在我对这个问题的研究中,看起来转发器的所有孩子都应该已经拥有这个了吗?

“NamingContainer属性在代码中可用于该类或派生类的任何实例。” (找到:here

我错过了什么?

这是我的转发器:

<asp:Repeater ID="repHW" runat="server" OnItemCommand="rep_ItemCommand">
        <HeaderTemplate>
            <table style="width:100%; padding-bottom:10px" id="HWtable">
                <tr style="font-weight: bold"><td>Product</td><td>Part Number</td><td>Cost</td><td>Unit Price</td><td>Quantity</td><td>Price</td><td>Delete</td></tr>
        </HeaderTemplate>
        <ItemTemplate>
                <tr>
                    <asp:HiddenField ID="Category" Value="Hardware" runat="server"/>
                    <td><asp:Label ID="Product" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Name") %>' /></td> <!--TODO: make this clickable to edit -->
                    <td><asp:Label ID="PartNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.PartNumber") %>' /></td>
                    <td><asp:Label ID="PartCost" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Cost") %>' /></td>
                    <td><asp:Label ID="UnitPrice" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Product.Price") %>' /></td>
                    <td><asp:Label ID="Quantity" runat="server" Text='<%# Eval("Quantity") %>' /></td>
                    <td><asp:Label ID="Price" runat="server" Text='<%# Eval("Total") %>' /></td>
                    <td><asp:Button class="btn btn-danger" ID="DeleteHardware" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%# Container.ItemIndex %>'/></td>
                </tr>
        </ItemTemplate>
        <FooterTemplate>
                <tr>
                    <asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
                    <td><SuggestComboBox runat="server" ID="AddProduct" AutoCompleteMode="SuggestAppend" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadHardwareProducts"/></td>
                    <td><asp:TextBox runat="server" ID="AddPartNumber" ClientIDMode="static"/></td>
                    <td><asp:TextBox runat="server" ID="AddPartCost" ClientIDMode="static"/></td>
                    <td><asp:TextBox runat="server" ID="AddUnitPrice" ClientIDMode="static"/></td>
                    <td><asp:TextBox runat="server" ID="AddQuantity" ClientIDMode="static"/></td>
                    <td><asp:Button class="btn btn-success" ID="AddHardware" runat="server" Text="Add" CommandName="Add" CommandArgument='<%# Container.ItemIndex %>' onClientClick="return EmptyFieldCheck('Hardware');"/></td>
                </tr>
            </table>    
        </FooterTemplate>
    </asp:Repeater>

这是我的功能我试图访问其他元素:

protected void ProductSelected(Object source, EventArgs e)
    {
        SuggestComboBox temp = (SuggestComboBox)source;

        List<Product> results = session.Query<Product>()
            .Where(x => x.Name == temp.Text)
            .ToList();


        if(results.Count > 0)
        {
            Product p = results[0];

            var repParent = temp.NamingContainer; //this broke

            TextBox partNum = (TextBox)repParent.FindControl("AddPartNumber");
            TextBox partCost = (TextBox)repParent.FindControl("AddPartCost");
            TextBox unitPrice = (TextBox)repParent.FindControl("AddUnitPrice");
            TextBox quantity = (TextBox)repParent.FindControl("AddQuantity");

            partNum.Text        = p.PartNumber;
            partCost.Text       = p.Cost.ToString();
            unitPrice.Text      = p.Price.ToString();
            quantity.Text       = p.DefaultQuantity.ToString();

        }
    }

0 个答案:

没有答案