Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gridview and Linq

Posted on 2009-05-07
10
Medium Priority
?
621 Views
Last Modified: 2013-11-11
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 VB.net 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".
0
Comment
Question by:drquan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24333818
When you said List Gridview, do you mean you are using a List as a datasource to the gridview?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24335689
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...
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24335777
If you are using a DataTable as the datasource to the List Gridview then you can try this

dim drow as datarow = LGridView.NewRow
drow(0)=somevalue
drow(1)=somevalue
...
LGridView.Rows.Add(drow)

If its not a datatable then comeback here and provide more information.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:drquan
ID: 24337550
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.  
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24337667
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.
0
 

Author Comment

by:drquan
ID: 24337787
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.

K
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24338602
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
w.id = blablabla
W.Text = blablabla
db.Widgets.InsertOnSubmit(W)
Grid1.DataSource = db.Widgets

Now when you need to save changes, just call this
db.submitchanges()
0
 

Author Comment

by:drquan
ID: 24339791
That works ok for Inserts.  What if a user adds a widget and then wishes to delete the widget (submitchanges has not been called)?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 24341106
In that case the alternative method is to use another list of T.
Dim WidgetList as new List(of Widget)

WidgetList.Add(W)
WidgetList.Remove(W)

Then when saving
for each W in WidgetList
      db.Widgets.InsertOnSubmit(W)
Next
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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