Solved

Gridview and Linq

Posted on 2009-05-07
10
612 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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