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

x
?
Solved

How do I make a copy of a asp.net/vb.net 2.0 gridview?

Posted on 2009-05-13
2
Medium Priority
?
404 Views
Last Modified: 2013-11-07
ASP.NET/VB.NET 2.0: I thougt I could just passing my gridview ByVal to my method would allow me to make changes to the gridview without the orginal one on my page being affected but it appears I was wrong. I need to take my gridview on my page, make some mods (hide some fields & change header/footer color) then send it in an email but once the email is sent, the gridview that I passed has the mods I made on the one I sent via email. How can I copy this gridview to send without messing with the one on my page?
0
Comment
Question by:techpr0
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 24378925
GridView objects are, just like any other objects, references. If you use ByVal instead of ByRef, all you are saying is that if you change the reference to the variable, it will not be reflected:

Sub Mail(ByVal grid As GridView)
     grid = New GridView()    ' will not override original gridview
End Sub

ByRef and ByVal in general have more meaning when used with value types like Integer, DateTime and Doubles.

Back to your question: you will have to clone the grid. Since there's no immediate way to do this, you will have to either create a new grid, or make the changes while sending mail, and revert the changes thereafter (i.e., by calling the PageLoad again, or the DoLoad function if you have one).

You can of course, let the new grid use the same datasource as the original grid.
0
 

Author Comment

by:techpr0
ID: 24379142
I wanted to email the exact version of the gridview that is on the page incase the user sorted it or something. In the case that it's sorted is also why I didn't use the datasource (sqldatasource) to bind to a new one to send. Am I correct in thinking that the gridview is what is sorted and not the datasource?

I guess I could send and then rebind. Once you rebind a gridview to a sqldatasource it loses the ability to sort correct? You then have to handle the sorting manually correct? Have any links laying around on handling 2.0 gridview sorting manually?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

972 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