HyperLinkColumn problem

  • Thread starter Thread starter Franck Diastein
  • Start date Start date
F

Franck Diastein

Hi,

I create from my CS code an HyperLinkColumn, and add it to a DataGrid
before binding data...

Then, I need to use text from that Column in ItemDataBound...

I do this:

e.Item.Cells[2].Text = e.Item.Cells[0].Text + "MyStuff";

the problem is that my Cell 2 only shows MyStuff instead of cell's 0
text AND MyStuff...

I think the problem cames from the fact that I create 'source' cell by
code, but I can't do it another way...

Any idea ?

TIA
 
Franck,

Read Your Hyperlink text like below.

( (Hyperlink)e.item.findcontrol("HyperlinkId")).Text.

The text you're trying to read from cell[0] returns the literal text
in the cell. The hyperlink you have added would be a control added to
the control tree with the cell as the parent tree.

-Souri
 
I understand what you say, but that doesn't work :-(

I have defined nothing in aspx side...

This is what I have done:

HyperLinkColumn hlcLink = new HyperLinkColumn();
hlcLink.HeaderText = "Rep";
hlcLink.DataTextField = "Name";
hlcLink.DataNavigateUrlField = "Name";
hlcLink.DataNavigateUrlFormatString = classes.appSettings.SvnURI + "{0}";

dgDirectories.Columns.AddAt(0,hlcLink );

I tried this:

e.Item.Cells[2].Text = ((HyperLink ) e.Item.FindControl("hlcLink")).Text;

But had this error:

Object reference not set to an instance of an object.
 
You need to find the control by its ID. Try setting an explict ID to
the control right after you create it and use it in FindControl.
 
I just noticed that you're trying to add a column not control in the
cell.
try the following

e.Item.Cells[2].Text = ((HyperLink)e.Item.Cells[0].Controls[0]).Text;

HTH,
Souri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top