Solved

Need to add to bound columns in a repeater control

Posted on 2004-09-23
3
823 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

621 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