?
Solved

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

Posted on 2004-09-04
9
Medium Priority
?
179 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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…

770 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