Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to add to bound columns in a repeater control

Posted on 2004-09-23
3
Medium Priority
?
824 Views
Last Modified: 2012-08-14
How can I add a third bound column in a Repeater that takes the sum of the following two bound columns in a repeater control?
<%# DataBinder.Eval(Container.DataItem, "sched_m") %></td>
<%# DataBinder.Eval(Container.DataItem, "sched_f") %></td>

0
Comment
Question by:Nobletucky2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12132862
I would use a datagrid instead, heres an example:

I would add a template column and make an itemdatabound subroutine to handle the OnItemDataBound event (put OnItemDataBound="DataGrid1_ItemDataBound" in the HTML source between the datagrid tags

Each time a row is added, it will call this subroutine and you can do math with each cell of the row(item)

    Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
         'assuming template column will be column #7 and the dropdown list is column 5 and the quantity is column 6
         e.item.cells(7).text = CStr(CDbl(e.item.cells(6).text) * CDbl(CType(e.item.cells(5).controls(0) ,DropDownList).SelectedItem.Text)
    End Sub

Regards,

Aeros
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 2000 total points
ID: 12132899
but here it is for a repeater since thats what you asked for:

Summations for a Repeater Control

As the item amounts are being calculated for each row of the Repeater they can also be totaled. At the completion of binding, then, the total value of inventory for all the products can be reported. This summation is added to the GetAmount() function.

Dim Total As Decimal = 0.00

Function GetAmount(Quantity As Decimal, Price As Decimal)

  Dim Amount As Decimal
  Amount = Quantity * Price
  Total += Amount
  Return FormatNumber(Amount, 2)

End Function

Note that a summation variable, Total, is declared globally and initialized outside the function. (If it were placed inside the function it would be reinitialized each time the function is called and would never accumulate a total.) Inside the function the line Total += Amount adds the calculated item amount to the Total. When all records are processed, Total holds their totaled amounts.

Now it is a matter of adding a total line to the end of the Repeater to report the inventory total. The revised <FooterTemplate> is shown below.

<FooterTemplate>
  <tr style="background-color:#A0A0A0; color:#FFFFFF; font-weight:bold;
      text-align:right">
    <td colspan="4">Total Value: </td>
    <td><%# GetTotal() %></td>
  </tr>
  </table>
</FooterTemplate>

The binding expression <%# GetTotal() %> is a call to function GetTotal() which returns the accumulated total. No arguments are passed to the function since it merely retrieves and formats the value stored in global variable Total. The following code is added to the page script.

Function GetTotal()

  Return FormatCurrency(Total)

End Function

The Repeater display now appears as shown below.

No.       Name       Price       Qty.       Amount
11111       Adobe Photoshop       345.95       10       3,459.50
22222       Adobe Illustrator       249.95       5       1,249.75
33333       Microsoft XP Upgrade       99.95       14       1,399.30
44444       Microsoft Office XP       699.99       9       6,299.91
55555       MacroMedia DreamWeaver       145.95       18       2,627.10
Total Value:       $15,035.56

http://it.maconstate.edu/tutorials/ASPNET/ASPNET08/aspnet08-04.aspx

Regards,

Aeros
0
 

Author Comment

by:Nobletucky2004
ID: 12132908
The report required too much formatting for a datagrid control so I'm stuck with the repeater.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question