Solved

Gridview and Linq

Posted on 2009-05-07
10
596 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
  • 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now