Solved

Need to add to bound columns in a repeater control

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

19 Experts available now in Live!

Get 1:1 Help Now