Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 13th, 2007, 07:35 AM
Authorized User
 
Join Date: Jul 2007
Location: Staten Island, NY, USA.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Return value of HyperLinkField

Hi,
   I am trying to return value from GridView HyperLinkField field
with the statement:

 foreach (GridViewRow gvr in userGV.Rows)
 {
   value = gvr.Cells[1].Text;
 }

but I am getting empty string.
Please advise what is wrong.

Thanks

VladZeem

  #2 (permalink)  
Old August 13th, 2007, 07:46 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. the cell has controls inside, not text... you will have to get the control you are looking for inside the cell...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #3 (permalink)  
Old August 13th, 2007, 08:11 AM
Authorized User
 
Join Date: Jul 2007
Location: Staten Island, NY, USA.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK,
    but exactly the same code is perfectlly works with BoundField.
And how can I get HyperLinkField from GridViewRow.Cells[i].Controls ?

  #4 (permalink)  
Old August 13th, 2007, 08:22 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

use findcontrol with the name of the control to find it inside a cell (or a row)...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #5 (permalink)  
Old August 13th, 2007, 09:13 AM
Authorized User
 
Join Date: Jul 2007
Location: Staten Island, NY, USA.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Gonzalo for hint,
but "findcontrol with the name of the control to find it inside a cell "
does not work - here is the solution:
if(gvr.Cells[0].HasControls())
{
    Control c = gvr.Cells[0].Controls[0];
    if(c is HyperLink)
    {
        HyperLink hl = new HyperLink();
        hl = (HyperLink)c;
        //this statement returns value of HyperLinkField:
        value = hl.Text;
    }
}

thanks again for pointing to the right direction.



  #6 (permalink)  
Old August 14th, 2007, 12:13 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Gonzalo is suggesting the following, which does work:

Instead of a hyperlink column, you can use a template column with a hyperlink control in it:

   <asp:hyperlink runat="server" id="lnkMyLink" />

Then in the code behind, you use find control to find the control:

   HyperLink hl = (HyperLink)gvr.FindControl("lnkMyLink");

-Peter
  #7 (permalink)  
Old August 14th, 2007, 12:17 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

thanks peter for saving me ;)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
  #8 (permalink)  
Old August 14th, 2007, 12:21 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

No problem, just helping to clarify.


Similar Threads
Thread Thread Starter Forum Replies Last Post
need some help please getting a return value merk ASP.NET 2.0 Basics 4 October 3rd, 2007 07:10 PM
Hyperlinkfield GuyB ASP.NET 1.0 and 1.1 Basics 0 September 5th, 2006 01:16 AM
Null Return value ITSPRO SQL Server ASP 1 July 27th, 2006 02:53 PM
asp:HyperLinkField color change vkv ASP.NET 2.0 Professional 0 July 6th, 2006 06:19 PM
Including variables in a Gridview's HyperLinkField rit01 ASP.NET 2.0 Basics 0 February 4th, 2006 05:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.