Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

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;
            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">
                            <table class="CostBox" width="100%">
                                    <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><td colspan="6"></td></tr>
                            <div style="height: 200px; overflow: auto;">
                            <table class="text" width="100%">
                                        <table cellpadding="0" cellspacing="0">
                                        <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>
                                        <table cellpadding="0" cellspacing="0">
                                        <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>
                                        <td><img src="../images/arrow.jpg" /></td></tr></table>
                                    <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>
Avatar of techExtreme
techExtremeFlag of India image

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

This problem has been solved!
Unlock 1 Answer and 31 Comments.
See Answers