Wrox Programmer Forums
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
Old June 6th, 2006, 09:08 AM
Authorized User
Join Date: Jul 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in Gridview Cell

Hello everyone!!
this is lalit.Im facing a problem in gridview control.
The problem is in the following line of code in C# code.

dRowBasicPortFolio[2] = "<A href='../EventsCalendar/default.aspx?company=" + dRow[13] + "'>" + dRow[3] + "</a>"

I want to display the content of dRow[3] between 2 plus as a hyperlink in a gridview column in VC# 2005 but its not working.

It is giving the result in string form instead of link to some other web page(say ../EventsCalendar/default.aspx).Iam getting the following string as a result which is

 "<A href='../EventsCalendar/default.aspx?company=" + dRow[13] + "'>" + dRow[3] + "</a>"

on a cell of a specific GridView column.
In short just tell me in which way by using the following code

dRowBasicPortFolio[2] = "<A href='../EventsCalendar/default.aspx?company=" + dRow[13] + "'>" + dRow[3] + "</a>"

how could i get the hyperlink (dRow[3]) get stored in dRowBasicPortFolio[2] DataRow. The problem is the whole string("<A href='../EventsCalendar/default.aspx?company=" + dRow[13] + "' value of dRow[3] ""</a>") is getting getting stored on dRowBasicPortFolio[2] and displayed on cells of a specific gridveiw column.
one thing to mention that iam getting the value of dRow[3] but not as a hyperlink on a gridview column.

I would specifically like to request Mr. DEEPESH JAIN and PLANOIE to carefully consider and solve my problem as they are the most experienced guys in problem solving in the forum
Please help me out if you can. Its very urgent.

Old June 14th, 2006, 08:54 AM
Authorized User
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez

You can just use the hyperlinkfield in the GridView control. You just need to set its parameters properly for it to be working the way you want it to. Here's my example.

DataTable dt = new DataTable();
        for (int i = 0; i < 5; i++)
            dt.Rows.Add(new string[] {"google", "http://www.google.com"});

        GridView1.DataSource = dt;
        HyperLinkField hfield = ((HyperLinkField)GridView1.Columns[0]);
        hfield.DataNavigateUrlFields = new string[]{dt.Columns[0].ColumnName,dt.Columns[1].ColumnName};
        hfield.DataNavigateUrlFormatString = "{1}";
        hfield.DataTextField = hfield.DataNavigateUrlFields[0];

I basically create a gridview control and add a hyperlinkfield. Paste this code into the PageLoad event and see how it work.

Hope this helps.

Aldwin Enriquez
"Dont you ever give up!"
Old August 1st, 2007, 04:08 AM
Registered User
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prashantbhale11

you r code is not working properly
it gives error:invallid argument at line HyperLinkField hfield = ((HyperLinkField)GridView1.Columns[0]);
also check this :
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

prashant bhale

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
GridView - cell wrapping - need help snufse ASP.NET 2.0 Basics 0 July 21st, 2008 04:53 PM
Accessing one cell from gridview Aker C# 1 May 22nd, 2008 03:13 PM
How to change the value of one cell in a GridView? jameslin288@yahoo.com ASP.NET 2.0 Basics 8 November 19th, 2006 01:12 PM

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