473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Gridview / Datatable - extract as String Variable

I am very new to VB.net / ASP and have spent hours and hours trying to solve what must be a simple problem - hopefully someone can point me in the right direction.

I have a gridview bound to an MS Access database. A user selects an item which is then added to a datatable, contents appear in a second gridview at the bottom of the page. (Yes it's a simple Shopping Cart) - there are four fields - ID, Product, Quantity, Cost. When the user has finished adding items I want to capture the contents of the second gridview (or the datatable) and transfer it to a multi line textbox on another page, which can then be printed or emailed. : Session("print") = xxxxx Server.Transfer("~/printorder.aspx")

Searching the net has found two export options (Export to Excel / Export to CSV) both these work (HTMLTextWriter) but save a file to disk which doesn't help.

Can anyone explain the best way of extracting the four fields in the datatable / gridview as strings, then adding / appending them to a variable. What is the best way to handle this - a loop, a streamwriter or any other options ??

Any VB examples to get me started would be much appreciated .... even C (I have found translation sites)

Thanks in advance.
Jul 8 '08 #1
2 1716
Curtis Rutland
3,256 Expert 2GB
Well, if you are adding rows to a DataTable, then you can easily loop through that DataTable and get at your values.

I'm not sure what your end goal is, so I just made an example where you add all values to one long string. But you can see what you need to do:
Expand|Select|Wrap|Line Numbers
  1. Dim table As New DataTable() 'just so I have a table to play with
  2. Dim row As DataRow
  3. Dim longstring As String
  4. longstring = ""
  5. For Each row In table.Rows
  6.     longstring = longstring & row(0)
  7.     longstring = longstring & row(1)
  8.     'and so forth
  9.     'or you can use the column name:
  10.     longstring = longstring & row("colName")
  11. Next
  12.  
Jul 8 '08 #2
You got me moving in the right direction - I can now extract the contents from the datatable and transfer them to another ASP page.
Thank-you for your help.
Jul 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
3
by: Lloyd Sheen | last post by:
Is there an example of VB code which will take a datasource and extract from that the needed info (columns etc.) to create the columns and then bind the data? This seems so much more difficult...
5
by: =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post by:
Hi All, I have a GridView inside the EditItemTemplate of a FormView. Both FormView and GridView are data bound using an ObjectDataSource. When the FormView's ObjectDataSource object has a...
25
by: premprakashbhati | last post by:
i want to have checkboxes in my gridview ...by checking it ,i can delete the row/rows.... so i have written code and got 2 Errors ...can anyone solve it... Error:1...'gridview.RetrieveItems()': not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.