Solved

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

Posted on 2009-05-13
2
402 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
[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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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:…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

632 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