Solved

how do I total a datagrid column using a template column and html textox

Posted on 2004-09-04
9
173 Views
Last Modified: 2010-04-23
Please help with a asp.net/vb.net answer.  I have a datagrid that on page load the dataset is loaded.  I have added a textbox(html) inside of the templateColumn/itemTemplate.  It will load every amount due but I need to capture a total of it in a textbox else where on the page.  I have never done this before and the only answers that I am find on the web are either c# or written for those that are dynamically filling data to the datagrid.

Is there a solution for this if your datagrid is load directly with the dataset, so I can call that column or the textbox and do a count?

Here is a snippet of the test code:

        Me.dgTest.DataSource = MyDS.Tables(0)
        Me.dgTest.DataBind()

        Me.txtSum.Text = Me.dgTest.Columns(3).Count.ToString
   
0
Comment
Question by:oshe127
  • 4
  • 3
  • 2
9 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 total points
Comment Utility
you would just loop through the rows summing column 3 ... then put the value in your text box ...

dim tmp as integer = 0
for each dr as datarow in MyDs.Tables(0)
    tmp += dr(3)
next
'tmp contains your total

for you are using paging then exclude the unseen rows.
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
you could also do this in the DataBinding event to catch only visible rows.
0
 

Author Comment

by:oshe127
Comment Utility
Thank you so much!  
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
no problem.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:keijerjh
Comment Utility
Hi,

Why don't you use the Compute function of the DataTable class.

oDataTable.Compute("SUM(ORDERED_QTY)","CUSTOMER_ID='Wallmart'")

Greetings,
Yelle
0
 

Author Comment

by:oshe127
Comment Utility
Yelle,

I can't get the .Compute to come up on my page as an option.  What do I have to inherit or import?
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
Compute is a method of the DataTable class ...
0
 
LVL 1

Expert Comment

by:keijerjh
Comment Utility
Hi,

Strange I see the problem. But it seems to be an hidden property when you access the table using the dataset.


The following code works.
------------------------------------------------------------------------
        Dim oDataSet As Data.DataSet
        Dim oDataTable As Data.DataTable
        Dim oDataRow As Data.DataRow

        oDataTable = New Data.DataTable
        With oDataTable
            .TableName = "ORDER_LINE"
            .Columns.Add("CUSTOMER_ID")
            .Columns.Add("ORDERED_QTY", GetType(Integer))
        End With
        oDataRow = oDataTable.NewRow
        oDataRow("CUSTOMER_ID") = "El Cheapo"
        oDataRow("ORDERED_QTY") = 14
        oDataTable.Rows.Add(oDataRow)
        oDataRow = oDataTable.NewRow
        oDataRow("CUSTOMER_ID") = "El Cheapo"
        oDataRow("ORDERED_QTY") = 20
        oDataTable.Rows.Add(oDataRow)
        oDataRow = oDataTable.NewRow
        oDataRow("CUSTOMER_ID") = "Wallmart"
        oDataRow("ORDERED_QTY") = 8
        oDataTable.Rows.Add(oDataRow)
        oDataRow = oDataTable.NewRow
        oDataRow("CUSTOMER_ID") = "Wallmart"
        oDataRow("ORDERED_QTY") = 9
        oDataTable.Rows.Add(oDataRow)

        oDataSet = New Data.DataSet
        oDataSet.Tables.Add(oDataTable)
        MsgBox(oDataSet.Tables("ORDER_LINE").Compute("SUM(ORDERED_QTY)", "CUSTOMER_ID='Wallmart'"))
0
 

Author Comment

by:oshe127
Comment Utility
keijerjh

This was the perfect answer for the other half of my problem from my original question, I just didn't know how to phrase it.  I entered a question for this answer that you gave so I could give you points for it.  I the question is marked for keijerjh: .  Please copy and paste the answer you gave me above so I can give you the points.

Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

12 Experts available now in Live!

Get 1:1 Help Now