Solved

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

Posted on 2009-05-13
2
396 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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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.…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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: …

758 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

19 Experts available now in Live!

Get 1:1 Help Now