This is a migrated thread and some comments may be shown as answers.

disappearing hyperlinks in a GridDataItem

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ervin
Top achievements
Rank 1
ervin asked on 24 Jun 2011, 08:28 PM

If dataitem.ItemIndex() = 1Then

If d
ataitem(columnName(1)).Text <>"nbsp" Then

link.Font.Underline = True

 

link.Text = dataitem(columnName(1)).Text

link.NavigateUrl = HyprUrl + monthyear(1)

dataitem(columnName(1)).Controls.Add(link)

End If

 


If
dataitem(columnName(2)).Text <> "nbsp" Then
l
ink.Font.Underline = True

link.NavigateUrl = HyprUrl + monthyear(2)

link.Text = dataitem(columnName(2)).Text

dataitem(columnName(2)).Controls.Add(link)

End If

 

If dataitem(columnName(3)).Text <>"&nbsp" Then

link.Font.Underline = True

 

link.NavigateUrl = HyprUrl + monthyear(3)

link.Text = dataitem(columnName(3)).Text

dataitem(columnName(3)).Controls.Add(link)

end if

 

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Jun 2011, 09:43 AM
Hello Ervin,

I am not quite sure where you are adding HyperLinks. Check the following forum thread which discussed similar scenario. Hope this helps.
Hyperlinks not retained on postback

Thanks,
Princy.
0
ervin
Top achievements
Rank 1
answered on 29 Jun 2011, 08:11 PM

Hi Princy,

Thanks for your reply.
I looked at your link but I am not sure if my problem is the same.
I have several ... dataitem(columnName(3)).Controls.Add(link)... lines to add the link but only the last one draws the link, the others dont... 

Here is my code:

Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

 
...some code here...

 

 

myTelerikBase.HyprPrintTrend(RadGrid1, dataItem, lsTargetURL, monthYear)

 

----------
Public Sub HyprPrintTrend(ByRef grid As RadGrid,ByRef item As GridDataItem, ByVal url As String, ByVal monthyear() As String)
Dim
HyprUrl As String = url

Dim dataitem As GridDataItem = item

Dim link As New HyperLink
Dim
index As Integer = 0
Dim
columnName(grid.MasterTableView.Columns.Count - 1) As String
Dim
value(grid.MasterTableView.Columns.Count - 1) As String
For Each
col As GridColumn In grid.MasterTableView.Columns
Dim
columnCount As Integer = grid.MasterTableView.Columns.Count

If col.ColumnType = "GridBoundColumn" Then
If
dataitem.ItemIndex() = 0 Then

 

columnName(index) = col.UniqueName

value(index) = dataitem(col.UniqueName).Text

End If
index += 1

 

Next

If dataitem(columnName(1)).Text <>"&nbsp" Then

link.Font.Underline = True 

 

link.Text = ...

link.NavigateUrl = ...

dataitem(columnName(1)).Controls.Add(link) 

End If 
If dataitem(columnName(2)).Text <> "&nbsp" Then

link.Font.Underline = True

link.NavigateUrl = ...

 

link.Text = ...

dataitem(columnName(2)).Controls.Add(link)

End If

If dataitem(columnName(3)).Text <>"&nbsp" Then

 link.Font.Underline = True

 

link.NavigateUrl = ...

link.Text = ...

dataitem(columnName(3)).Controls.Add(link)

End If

If dataitem(columnName(4)).Text <> "&nbsp" Then

 

link.Font.Underline = True

link.NavigateUrl = ...

 

link.Text = ...

dataitem(columnName(4)).Controls.Add(link) *****
End If

***** Only the starred one draws the link, if I remove it the previous one will draw the link, goes like that..
Thanks,

Ervin

0
Daniel
Telerik team
answered on 05 Jul 2011, 08:52 AM
Hello Ervin,

No viewstate will be tracked for controls added on ItemDataBound. You have to add your controls on ItemCreated and then populate them on ItemDataBound.
I suggest that you have a look at the link posted by Princy.

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
ervin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
ervin
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or