[英]How to check whether the particular text present in GridHyperLink's NavigateUrl, when the user clicks on the link?
I have a hyper link in the grid like below 我在网格中有一个超级链接,如下所示
`<telerik:GridHyperLinkColumn HeaderText="Website Link" DataTextField="LinkAddress" DataTextFormatString="{0}" DataNavigateUrlFields="LinkAddress" DataNavigateUrlFormatString="{0}"
ItemStyle-VerticalAlign="Top" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Small" HeaderStyle-ForeColor="Black" Target="_blank" >`
Now when the user clicks on the link in the grid (on the screen), I should check whether the link contains the text "http://" or not , if not I should add that text before the link (dynamically ) in my aspx page (using javascript) and then redirect to that webaddress. 现在,当用户单击网格(在屏幕上)中的链接时,我应该检查链接是否包含文本“ http://”,否则,应该在我的链接之前(动态地)添加该文本。 aspx页面(使用javascript),然后重定向到该网址。
Now how to achieve this, could anyone help me, Thanks ! 现在如何实现这一目标,谁能帮助我,谢谢!
There are multiple ways to do this. 有多种方法可以做到这一点。 I would do it in the code behind in the grids ItemDataBound event so you don't have to call a javascript function.
我会在网格ItemDataBound事件后面的代码中执行此操作,因此您不必调用javascript函数。
Private Sub grid_ItemDataBound(sender As Object, e As GridItemEventArgs)
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
Dim link As HyperLink = DirectCast(item("ColumnUniqueName").Controls(0), HyperLink)
Dim sOldNavigateUrl as String = link.NavigateUrl
If Not ((sOldNavigateUrl.Contains("http://") Or sOldNavigateUrl.Contains("https://")) Then
link.NavigateUrl = "http://" & sOldNavigateUrl
End If
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.