Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-04
9
Medium Priority
?
180 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
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 1000 total points
ID: 11982857
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
ID: 11982858
you could also do this in the DataBinding event to catch only visible rows.
0
 

Author Comment

by:oshe127
ID: 11986130
Thank you so much!  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11986274
no problem.
0
 
LVL 1

Expert Comment

by:keijerjh
ID: 11999387
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
ID: 12006850
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
ID: 12006917
Compute is a method of the DataTable class ...
0
 
LVL 1

Expert Comment

by:keijerjh
ID: 12006971
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
ID: 12011114
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

609 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