I have a repeater that displays products, and the footer is input fields where you can choose a product from a db and add it to the repeater. The first field of the add line in the footer is a RadComboBox (with product names) and I want to update the other input fields with info from the db when SelectedIndexChanged for that combobox.
The problem is finding those other controls in my code-behind function.
protected void ProductSelected(Object source, EventArgs e)
{
RadComboBox temp = (RadComboBox)source;
Product p = session.Query<Product>()
.Where(x => x.Name == temp.SelectedItem.Text)
.FirstOrDefault();
var repParent = temp.Parent;
//var repParent = ((UpdatePanel)temp.NamingContainer.FindControl("UpdateHardwareLine")).ContentTemplateContainer;
((TextBox)repParent.FindControl("AddPartNumber")).Text = p.PartNumber;
((TextBox)repParent.FindControl("AddPartCost")).Text = p.Cost.ToString();
((TextBox)repParent.FindControl("AddUnitPrice")).Text = p.Price.ToString();
((TextBox)repParent.FindControl("AddQuantity")).Text = p.DefaultQuantity.ToString();
}
I've tried this 2 ways. At first I put the UpdatePanel in the footer of the repeater, and I changed repParent to the commented version. This produced some really weird results where it updated the input fields, but now they're above my entire repeater o_0?
Then I pulled the updatepanel out of the repeater, and it updates, but it refreshes the entire page. I would settle for just updating the footer, but it'd be neat to get those add/delete buttons working in the same update panel. How should I go about setting this up so it just refreshes for whats in this well?
as requested;
<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:UpdatePanel ID="UpdateHardwareLine" updatemode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddProduct" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:HiddenField ID="AddCategory" Value="Hardware" runat="server"/>
<td><telerik:RadComboBox runat="server" ID="AddProduct" ClientIDMode="static" Filter="Contains" EnableLoadOnDemand="true" AutoPostBack="true" OnSelectedIndexChanged="ProductSelected" OnDataBinding="LoadProductsByCategory"/></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='<%# DataBinder.Eval(Container, "ItemIndex") %>' onClientClick="return EmptyFieldCheck('Hardware');"/></td>
</ContentTemplate>
</asp:UpdatePanel>
</tr></table>
</FooterTemplate>
</asp:Repeater>