HyperLink Field Problem

S

shapper

Hello,

In my GridView I have a HyperLink Field where I set the
DataNavigateUrlFormaString

MyHyperLinkField.DataNavigateUrlFormatString =
"~\RSS.ashx?Channel={0}&Culture=" &
System.Threading.Thread.CurrentThread.CurrentCulture.ToString()

I believe {0} retrieves the value of my datasource column with index 0.
That value is "News".

What I get when I copy the link when previewing the page is:

http://localhost:1717/JaquelineRoxoAtelier 2006a/RSS.ashx?c=News

The part "http://localhost:1717/JaquelineRoxoAtelier 2006a/" is the
web site url in my localhost but then I can't see the culture value and
everything else is strange.

In my GridView all the QueryStrings I am building look strange and
don't work.

Could somebody help me out?

Thanks,

Miguel
 
C

Cowboy \(Gregory A. Beamer\)

{0} does not correspond to a particular field in the datatable. It is the
first item bound to the particular field in the Grid view. Open the designer
back up and bind at least one field to that column. That field will fill the
{0} in teh url string.

If you are in code behind, you can set the bound field, as well.

NOTE: The GridView auto binding should be turned off when you start binding
in this manner.
 
S

shapper

Hi Gregory,

I tried to fix this but after many hours I am having the same problem
or getting new problems. I will post my complete code. Could you,
please, take a look and tell me what am I doing wrong? I added "******"
to the code lines which I think interfer with the QueryString.

The GridView is all defined at runtime.

Private Sub gvRSSChannels_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles gvRSSChannels.Init

' Define gvRSSChannels properties
With gvRSSChannels
.AutoGenerateColumns = False
.BorderStyle = BorderStyle.None
.DataSource = gvRSSChannels_DataSource()
.GridLines = GridLines.Horizontal
.ShowFooter = False
.ShowHeader = False
End With

' Create, define and add icon template field
Dim tfIcon As New TemplateField
tfIcon.ItemTemplate = New gvRSSChannelsTemplate(Me,
ListItemType.Item)
gvRSSChannels.Columns.Add(tfIcon)

' Create, define and add name bound field
Dim bfName As New BoundField
With bfName
.DataField = "Channel"
End With
gvRSSChannels.Columns.Add(bfName)

' Create, define and add url hyperlink field
Dim hfUrl As New HyperLinkField
With hfUrl
.DataTextFormatString =
"Me.GetLocalResourceObject(""String.{0}"").ToString()"
.DataNavigateUrlFormatString = "~\RSS.ashx?Channel={0}&Culture="
& System.Threading.Thread.CurrentThread.CurrentCulture.ToString()
End With
gvRSSChannels.Columns.Add(hfUrl)

End Sub

Private Sub gvRSSChannels_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles gvRSSChannels.Load

' Bind GridView to its data source
If Not IsPostBack Then
gvRSSChannels.DataBind()
End If

End Sub

----- Template CLASS ----

' rRSSChannelsTemplate
Public Class gvRSSChannelsTemplate
Implements ITemplate

' Define parent page
Private parent As RSS

' Define template type
Private type As ListItemType

' Create new template
Sub New(ByVal parentPage As RSS, ByVal templateType As
ListItemType)

' Define parent page
parent = parentPage

' Define template type
type = templateType

End Sub

' Define template
Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn

' Select template type
Select Case type

Case ListItemType.Header ' Header template

Case ListItemType.Item ' Item template

' Create item template controls
Dim rtrhlIcon As New RssToolkit.RssHyperLink

' Add item template controls handlers
AddHandler rtrhlIcon.DataBinding, AddressOf
rtrhlIcon_DataBinding

' Add item template controls to gvRSSChannels
container.Controls.Add(rtrhlIcon)

Case ListItemType.EditItem ' Edit Item
template

Case ListItemType.Footer ' Footer template

End Select
End Sub

' rtrhlIcon data binding and properties
Private Sub rtrhlIcon_DataBinding(ByVal sender As Object, ByVal e
As System.EventArgs)

' Define rtrhlIcon
Dim rtrhlIcon As RssToolkit.RssHyperLink
rtrhlIcon = CType(sender, RssToolkit.RssHyperLink)

' Define rtrhlIcon container
Dim container As GridViewRow
container = CType(rtrhlIcon.NamingContainer, GridViewRow)

' Define rtrhlIcon properties
With rtrhlIcon
.ChannelName = Me.parent.GetLocalResourceObject("String." &
DataBinder.Eval(container.DataItem, "Channel")).ToString()
.ImageUrl =
Me.parent.GetLocalResourceObject("rtrhlIcon.ImageUrl").ToString()
.IncludeUserName = "False"
.NavigateUrl = "~/RSS.ashx?Channel=" &
DataBinder.Eval(container.DataItem, "Channel") & _
"&Culture=" &
System.Threading.Thread.CurrentThread.CurrentCulture.ToString())
.ToolTip = Me.parent.GetLocalResourceObject("String." &
DataBinder.Eval(container.DataItem, "Channel")).ToString()
End With

End Sub

End Class

Thank You Very Much,
Miguel
 
S

shapper

Hi Gregory,

I read what you wrote and I have my autobinding turned off.
I also tried to not use {0} but I am having some problems there.

I am working on this for hours and everything looks fine.
It's just that all the links show messed up.
The GridView is all defined at runtime.

Could you, please, take a look at my code and tell me what am I doing
wrong?
I point with "****" the code line which I think are giving me problems
with QueryStrings.

Private Sub gvRSSChannels_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles gvRSSChannels.Init

' Define gvRSSChannels properties
With gvRSSChannels
.AutoGenerateColumns = False
.BorderStyle = BorderStyle.None
.DataSource = gvRSSChannels_DataSource()
.GridLines = GridLines.Horizontal
.ShowFooter = False
.ShowHeader = False
End With

' Create, define and add icon template field
Dim tfIcon As New TemplateField
tfIcon.ItemTemplate = New gvRSSChannelsTemplate(Me,
ListItemType.Item)
gvRSSChannels.Columns.Add(tfIcon)

' Create, define and add name bound field
Dim bfName As New BoundField
With bfName
.DataField = "Channel"
End With
gvRSSChannels.Columns.Add(bfName)

' Create, define and add url hyperlink field
Dim hfUrl As New HyperLinkField
With hfUrl
.DataTextFormatString =
"Me.GetLocalResourceObject(""String.{0}"").ToString()"
.DataNavigateUrlFormatString = "~\RSS.ashx?Channel={0}&Culture="
& System.Threading.Thread.CurrentThread.CurrentCulture.ToString()
' ****
End With
gvRSSChannels.Columns.Add(hfUrl)

End Sub

Private Sub gvRSSChannels_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles gvRSSChannels.Load

' Bind GridView to its data source
If Not IsPostBack Then
gvRSSChannels.DataBind()
End If

End Sub

---- Template CLASS ----

' rRSSChannelsTemplate
Public Class gvRSSChannelsTemplate
Implements ITemplate

' Define parent page
Private parent As RSS

' Define template type
Private type As ListItemType

' Create new template
Sub New(ByVal parentPage As RSS, ByVal templateType As
ListItemType)

' Define parent page
parent = parentPage

' Define template type
type = templateType

End Sub

' Define template
Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn

' Select template type
Select Case type

Case ListItemType.Header ' Header template

Case ListItemType.Item ' Item template

' Create item template controls
Dim rtrhlIcon As New RssToolkit.RssHyperLink

' Add item template controls handlers
AddHandler rtrhlIcon.DataBinding, AddressOf
rtrhlIcon_DataBinding

' Add item template controls to gvRSSChannels
container.Controls.Add(rtrhlIcon)

Case ListItemType.EditItem ' Edit Item
template

Case ListItemType.Footer ' Footer template

End Select
End Sub

' rtrhlIcon data binding and properties
Private Sub rtrhlIcon_DataBinding(ByVal sender As Object, ByVal e
As System.EventArgs)

' Define rtrhlIcon
Dim rtrhlIcon As RssToolkit.RssHyperLink
rtrhlIcon = CType(sender, RssToolkit.RssHyperLink)

' Define rtrhlIcon container
Dim container As GridViewRow
container = CType(rtrhlIcon.NamingContainer, GridViewRow)

' Define rtrhlIcon properties
With rtrhlIcon
.ChannelName = Me.parent.GetLocalResourceObject("String." &
DataBinder.Eval(container.DataItem, "Channel")).ToString()
' ****
.ImageUrl =
Me.parent.GetLocalResourceObject("rtrhlIcon.ImageUrl").ToString()
.IncludeUserName = "False"
.NavigateUrl = "~/RSS.ashx?Channel=" &
DataBinder.Eval(container.DataItem, "Channel") & _
"&Culture=" &
System.Threading.Thread.CurrentThread.CurrentCulture.ToString())
.ToolTip = Me.parent.GetLocalResourceObject("String." &
DataBinder.Eval(container.DataItem, "Channel")).ToString()
' ****
End With

End Sub

End Class

Thank You Very Much,
Miguel
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top