Re: Creating Hyperlink in DataGrid Column

Tech-Archive recommends: Speed Up your PC by fixing your registry



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!
>>
>>
>>.
>>


.



Relevant Pages

  • Re: Datagrid display problem
    ... I chose to avoid this problem by having a datagrid for each table. ... to get rid of a cell in a table that has the cursor in it. ... changing the datasource to another table and displaying its cells, ... Dim myDataColumn As DataColumn ...
    (microsoft.public.dotnet.languages.vb)
  • DataRow Rowstate and drag and drop
    ... I'm displaying a datagrid ... when the user enters a certain text cell on a row it does a lookup of possible matches. ... But this does not leave the DataSets Rowstate for that Row as Modified? ...
    (microsoft.public.dotnet.framework.adonet)
  • Creating Hyperlink in DataGrid Column
    ... I'm using the DataGrid with AutoGenerateColumns set to false and choosing ... Say I have a query: ... I am only displaying the Name column, ... access the ID column from my query once I am in this event handler. ...
    (microsoft.public.dotnet.framework.aspnet)
  • DataGrid with drag and drop, need to control rowstate.
    ... I'm displaying a datagrid ... when the user enters a certain text cell on a row it does a lookup of possible matches. ... The grid works when the certain text cell that is the source of the lookup is keyboard edited or other grid ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: DataGrid with drag and drop, need to control rowstate.
    ... I'm displaying a datagrid ... when the user enters a certain text cell on a row it does a lookup of possible matches. ... The grid works when the certain text cell that is the source of the lookup is keyboard edited or other grid ...
    (microsoft.public.dotnet.framework.windowsforms)