Gridview and Linq

I have two gridviews and a Save Button.  One Gridview for Items and the other for a list.  The Items Gridview has a linkbutton template field and when you click on an item it should add it to the List Gridview.  The List Gridview may already have items on it from previously saving the List.  I am using and Linq to accomplish this.  My issue is:  I would like to update the List Gridview without committing the changes to the database until I click "Save".
Who is Participating?
CodeCruiserConnect With a Mentor Commented:
In that case the alternative method is to use another list of T.
Dim WidgetList as new List(of Widget)


Then when saving
for each W in WidgetList
When you said List Gridview, do you mean you are using a List as a datasource to the gridview?
Bob LearnedCommented:
I believe that the statement, "One Gridview for Items and the other for a list", just means that the "List GridView" is the 2nd GridView, not a ListBox or ListView control...
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

If you are using a DataTable as the datasource to the List Gridview then you can try this

dim drow as datarow = LGridView.NewRow

If its not a datatable then comeback here and provide more information.
drquanAuthor Commented:
Thanks for the replies!!

The gridview is just a gidview of the items on a list.  I've used the DataTable solution in the past, however,  I was hoping to use an Entity provided by the Linq Datamodel to accomplish this.  
That's what my previous question was. Is it a List<of T> ? What type of objects are in the list? Please show us the exact datatypes of the list and the types in the list.
drquanAuthor Commented:
Let me try and clarify.
I have two Gridveiws.  One for available widgets and the other for selected widgets.
The "available widgets" Gridview has LinkButton Controls.  When you Click on the Link Button, the widget gets added to the second Gridview ("selected widgets").  I would like the user to be able to add/delete widgets without committing the changes to the database.  Once a user has finished adding and deleting widgets, they then can Click on a "Save" Button and all changes will be committed to the database.  
I can accomplish this via a SQLDataSource and DataTable, however, I would like to use the Entity Framework instead.

I am not sure about entity framework but as the original question is about LINQ so i would use LINQ here.
You can set a datasource to the grid like this
Grid1.DataSource = db.Widgets
where db is a DataContext class and Widgets is a Table(of Widget) variable within db. Widget is the actual class representing the Widget table.
To add a new item, you could do something like this

Dim W as new Widget = blablabla
W.Text = blablabla
Grid1.DataSource = db.Widgets

Now when you need to save changes, just call this
drquanAuthor Commented:
That works ok for Inserts.  What if a user adds a widget and then wishes to delete the widget (submitchanges has not been called)?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.