This is a migrated thread and some comments may be shown as answers.

Assign all data to grid from client

1 Answer 19 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 14 Nov 2008, 01:06 AM
How can I use the grid to assign data from the client side only?

I want to use if for a shopping cart: I'll add items via javascript to the grid when the user clicks on 'add to cart' for an item. But I'd rather not go back to the server with a postback for cart adds.

so, for example (roughly):

//...page init...  
var items = new Array()   
 
//...elsewhere when add item clicked...  
var item = {"PartNumber", partNumber, "Name":partName};
addToCart(item);  
 
function addToCart(item) {  
  var cartGrid = $find("cartGridId");  
  if(cartGrid) {  
    items.push(item);  
    cartGrid.DataSource = items;  
  }  

I already know this isn't working, but it gives the sense of what I'd like to do.

Any guidance?

Thanks!
Scott

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Nov 2008, 05:29 AM
Hello Scott,

You can try out the following to insert the array of items to the grid on client side.
js:
        function addToCart(item) 
        {          
             items.push(item);   
             var tableView = $find("<%= cartGrid.ClientID%>").get_masterTableView(); 
             tableView.set_dataSource(items); 
             tableView.dataBind();            
        
        }  

Also go through this online demo to understand better how to get insert/update/delete on client side.
Thanks
Princy.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or