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
Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create an MVC5, Razor Widget 2 26
hbo knew my windows software 4 62
SQL Query Help Top 1 and Distinct? 6 35
transition to visual .net from vb6 5 37
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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