Re: Creating Hyperlink in DataGrid Column
- From: "epigram" <nospam@xxxxxxxxxx>
- Date: Thu, 14 Apr 2005 10:49:07 -0400
Hi Elton,
I'm getting an error:
"System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values. Parameter name: index" with regard to the statement:
HyperLink link = (HyperLink) nameCell.Controls[0];
This cell is a BoundColumn. Any ideas what could be happening here?
Thanks.
"Elton Wang" <anonymous@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:14f701c5408a$43b66aa0$a501280a@xxxxxxxxxx
> Hi epigram,
>
> You can use HyperLinkColumn. And create url in
> datagrid_ItemDataBound event:
>
> if (e.Item.ItemType == ListItemType.AlternatingItem ||
> e.Item.ItemType = ListItemType.Item )
> {
> DataRowView drv = (DataRowView)e.Item.DataItem;
> TableCell nameCell = e.Item.Cells[nameIndex];
> HyperLink link = (HyperLink) nameCell.Controls[0];
> link.NavigateUrl = "CompanyDetails.aspx?id=" + drv
> ["ID"].ToString();
> }
>
> HTH
>
> Elton Wang
> elton_Wang@xxxxxxxxxxx
>
>>-----Original Message-----
>>I'm using the DataGrid with AutoGenerateColumns set to
> false and choosing
>>which columns I want in the grid by using the <Columns>
> attribute. What I
>>want to do is to create a hyperlink out of one of the
> columns that I am
>>displaying, but in order to build this link, I need a
> value that is in my
>>SELECT clause, but is not being displayed via a
> BoundColumn.
>>
>>Say I have a query: SELECT ID, Name FROM Companies
>>
>>Here, ID is the PK. I am only displaying the Name
> column, but I want the
>>Name to be a hyperlink to a "details" page for the
> company. So, I want to
>>build a link such as "CompanyDetails.aspx?id=1234".
>>
>>I know there is an event I can override to change how the
> Name cell in the
>>DataGrid is rendered. What I don't know is how I can
> programmatically
>>access the ID column from my query once I am in this
> event handler.
>>
>>Thanks!
>>
>>
>>.
>>
.
- Follow-Ups:
- Re: Creating Hyperlink in DataGrid Column
- From: Elton Wang
- Re: Creating Hyperlink in DataGrid Column
- References:
- Creating Hyperlink in DataGrid Column
- From: epigram
- Creating Hyperlink in DataGrid Column
- From: Elton Wang
- Creating Hyperlink in DataGrid Column
- Prev by Date: Re: How to integrate Profile with Membership
- Next by Date: Re: Accessing a windows Service from a web form
- Previous by thread: Re: Creating Hyperlink in DataGrid Column
- Next by thread: Re: Creating Hyperlink in DataGrid Column
- Index(es):
Relevant Pages
|