Solved

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

Posted on 2004-09-04
9
174 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
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
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11986274
no problem.
0
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.

 
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

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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 …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

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

15 Experts available now in Live!

Get 1:1 Help Now