Solved

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

Posted on 2004-09-04
9
175 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

10 Experts available now in Live!

Get 1:1 Help Now