Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 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

11 Experts available now in Live!

Get 1:1 Help Now