troubleshooting Question

Get row values and calculate in ascx Repeater

Avatar of Al230762
Al230762Flag for United Kingdom of Great Britain and Northern Ireland asked on
.NET ProgrammingASP.NET
31 Comments1 Solution2097 ViewsLast Modified:
On a ascx web page I have a Repeater. The Repeater has a DDL, 3 text boxes and a "Save" button. When a user updates a number in text box "txtRate" or in text box "txtHours" in any row I want a client-side javascript function to multiply the values in those two boxes and put the result in text box "txtCost" in that same row- no postbacks involved - postback will happen when the user clicks "Save". Obviously this calculation must only apply to that particular row.
I have a javacsript function that only fires on the first row of the repeater and no other but then it applies the calculation to the "txtCost" in the SECOND row!

Function and Repeater code are attached. Any advice gratefully received.
function RPTcalculateCost()
    {
        var a = document.getElementById("ctl00$ContentPlaceHolder1$IR$ctl00$rptJobDetails$ctl01$txtRate");
        var b = document.getElementById("ctl00$ContentPlaceHolder1$IR$ctl00$rptJobDetails$ctl02$txtHours");
        var c = document.getElementById("ctl00$ContentPlaceHolder1$IR$ctl00$rptJobDetails$ctl02$txtCost");
        if (b.value == '')
        {
            c.value = 0;
        }
        else
        {
            c.value = parseFloat(a.value) * parseFloat(b.value);
        }
    }   
 
<td colspan="2" style="height: 19px">
                    <asp:Panel runat="server" ID="pnlJobDetails" DefaultButton="btnHidSave">
                        <asp:Repeater ID="rptJobDetails" runat="server">
                            <HeaderTemplate>
                            <table class="CostBox" width="100%">
                                <tr>
                                    <td align="left" style="width: 80px; height: 24px">&nbsp;&nbsp;Staff</td>
                                    <td align="left" style="width: 95px; height: 24px">Staff type</td>
                                    <td align="left" style="width: 55px; height: 24px">Hourly rate</td>
                                    <td align="left" style="width: 35px; height: 24px">Available hours</td>
                                    <td align="left" style="width: 85px; height: 24px">Cost</td>
                                    <td style="height: 24px" >&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</td>
                                </tr>
                                <tr><td colspan="6"></td></tr>
                            </table>
                            <div style="height: 200px; overflow: auto;">
                            <table class="text" width="100%">
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <table cellpadding="0" cellspacing="0">
                                        <tr><td>
                                        <div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
                                        <asp:DropDownList runat="server" ID="ddlStaff" Enabled="false"  Font-Size="XX-Small" Width="180px"></asp:DropDownList>
                                        </div></td>
                                        </tr></table>
                                    </td>
                                    <td>
                                        <table cellpadding="0" cellspacing="0">
                                        <tr><td>
                                        <div class="os" style="width:80px;overflow:hidden;border-right:1px solid gray">
                                        <asp:DropDownList runat="server" ID="ddlStaffType2" Font-Size="XX-Small" Width="230px" AutoPostBack="true"></asp:DropDownList>
                                        </div></td>
                                        <td><img src="../images/arrow.jpg" /></td></tr></table>
                                    </td>
                                    <td><asp:TextBox runat="server" CssClass="costbox" ID="txtRate" Width="55px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "HourlyRate")%>></asp:TextBox></td>
                                    <td><asp:TextBox runat="server" CssClass="textbox2" ID="txtHours" Width="35px" Font-Size="XX-Small" OnKeyUp="javascript:RPTcalculateCost();" Text= <%# DataBinder.Eval(Container.DataItem, "AvailableHours")%> ></asp:TextBox></td>
                                    <td><asp:TextBox runat="server" CssClass="costbox" ID="txtCost" Width="75px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "Cost")%> ></asp:TextBox></td>
                                    <td><asp:TextBox runat="server" CssClass="textbox2" ID="intCount" Visible="false" Width="1px" Font-Size="XX-Small" Text= <%# DataBinder.Eval(Container.DataItem, "interventionCount")%> ></asp:TextBox></td>
                                    <td><asp:Button runat="server" ID="btnDelete" Width="18px" Height="18px" CssClass="button" Text="X" ForeColor=red Font-Bold=true CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> /></td>
                                    <td><asp:Button runat="server" ID="btnSave" Height="18px" Width="28px" CssClass="button" Text="Save" Font-Size="10px" ToolTip="Save changes" ForeColor="green" Font-Bold="true" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="save" /></td>
                                    <td><asp:Button runat="server" ID="btnPrintDetail" Width="18px" Height="18px" CssClass="button" Text="?" ForeColor=DarkBlue Font-Bold=true ToolTip="Print details" CommandArgument= <%# DataBinder.Eval(Container.DataItem, "ID") %> CommandName="print" BackColor="LightBlue" Font-Names="Tahoma" /></td>
                                </tr> 
                            </ItemTemplate>
                            <FooterTemplate>
                                </table></div>
                            </FooterTemplate>
                        </asp:Repeater>
                    </asp:Panel>
ASKER CERTIFIED SOLUTION
techExtreme

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 31 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 31 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros