Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Gridview and Linq

Posted on 2009-05-07
10
Medium Priority
?
629 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Screencast - Getting to Know the Pipeline

971 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