Solved

Need to add to bound columns in a repeater control

Posted on 2004-09-23
3
811 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
  • 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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now