Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › How to bind data without database source?
New Posts  All Forums:Forum Nav:

How to bind data without database source?

post #1 of 16
Thread Starter 
I know how to tie a datasource such as a sql database to gridview, but how do I provide information to gridview without processing data from a database? I have store information into session object. How do I bind each session object's data to gridview?
Edited by Buster - 4/25/12 at 10:14am
post #2 of 16
You just need to have a tabular collection object like a Dataset, datatable or a generic List to name a few in your session . Then you can bind it to your gridview something like YourGridview.DataSource = YourDatatable; YourGridview.Databind();
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASUS - P8Z68-V/GEN3 GTX 560 Ti DDR3 - 8G 
Hard DriveOSMonitorPower
1 TB Win 7 x64 Dell ST2320L Corsair 750TX 
Case
Coolermaster 310 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASUS - P8Z68-V/GEN3 GTX 560 Ti DDR3 - 8G 
Hard DriveOSMonitorPower
1 TB Win 7 x64 Dell ST2320L Corsair 750TX 
Case
Coolermaster 310 
  hide details  
Reply
post #3 of 16
Thread Starter 
I am trying to implement a shopping cart. On my product page, I have setup session objects to store product name, quantity, price. I use gridview on my cart page. I want to get the session information and bind it to gridview and if the product name is the same, just increment the quantity instead of creating another row for the same product. How would you set this up? What is the common way of implementing a shopping cart? I just need some ideas. Thanks!
post #4 of 16
  1. Why are you using Session Objects to store your products? A dataset/datatable would be so much better/easier to work with.
  2. Why do you have products with the same name? It should just be one entry, figuring out quantities should not be done via sessions. It should be done during the database query or calculated before you put it into a dataset or session.

If you really want to, you can bind gridviews to sessions with
Code:
GridView1.DataSource = Session["Source"];
 GridView1.DataBind();

depending on how you stored it into the session, you may need to convert it to something gridview can use.
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
post #5 of 16
Thread Starter 
On my product page, I use listview that reads the product information from a database. The columns include name, price, description, quantity. Each of them are a separate label control in listview. I have some code behind that will find the controls and assign each column values into their own session objects when I clicked on the add to cart button. Also, it will transfer me to my cart page. On the cart view page, I want to bind these session objects into their own column. If the same product is added twice, I want to increment the quantity instead of adding the same product twice.
post #6 of 16
Ok, now that explained your process, I can see what you are trying to do.

How are you retrieving the data out of the database? With SqlDataSource, DBObject, etc.? Is it a dataset/datatable?

How are you storing the products into Session? As List, dataset, datatable? This will determine how to bind it back to a Gridview.

For the 'adding product twice,' you should have another column in the session with 'quantity' if the product ID is in the session, increment the quantity column and update the session.
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
post #7 of 16
Thread Starter 
I am retrieving data out of sql database. I haven't figure how to store the products into session. What do you suggest?
post #8 of 16
Thread Starter 
The reason I said I haven't figure out how to store the products into session is because I was trying to implement this http://net.tutsplus.com/tutorials/other/build-a-shopping-cart-in-aspnet/.

The thing about this is that the product information is retrieve from the product class which I don't want because I need to get the latest information from the database from the product page session objects.
post #9 of 16
Quote:
Originally Posted by Buster View Post

I am retrieving data out of sql database. I haven't figure how to store the products into session. What do you suggest?

How are you retrieving data out of the database? How are you connecting to the database? I don't know how to help you if I don't know how you are processing the data. That tutorial uses an object, that's fine too.

For example, I have class that handles running my stored procedures with SqlDataAdapter that fills and returns a DataSet to me.

storing into a session is basically :
Code:
Session["name"] = whatever;
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
Main PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k Asus Maximus IV Gene-Z MSI 6950 2gb Unlocked Ref GSkill Ripjaws X 8GB CL8 
Hard DriveOSMonitorKeyboard
Crucial M4 128GB Windows 7 Ult Samsung 24" ToC Das Professional Silent 
PowerCaseMouse
Seasonic X750 Corsair 650d Logitech G700 
  hide details  
Reply
post #10 of 16
Thread Starter 
I use a sqldatabase control to load a sql database then use listview to connect to the sqldatabase control
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › How to bind data without database source?