Solved

Need to add to bound columns in a repeater control

Posted on 2004-09-23
3
822 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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