简体   繁体   English

当用户单击链接时,如何检查GridHyperLink的NavigateUrl中是否存在特定文本?

[英]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.

相关问题 如何检查这是否是用户第一次单击JSP中的链接? - How to check if it's the first time the user clicks on a link in JSP? 用户单击任何链接时显示文本 - Display text when user clicks on any link 如何检查特定字符串中是否存在任何特殊字符 - how to check whether any special character is present in a particular string 用户点击链接时如何设置倒数? - How to set a countdown when user clicks on a link? 用户单击链接时如何传递参数 - How to pass a parameter when user clicks a link 检查用户的系统是否可以看到特定的表情符号? - Check whether user's system can see a particular Emoji? 当用户在编辑后单击链接时,如何从HTML文本字段捕获更改事件? - How can I catch a change event from an HTML text field when a user clicks on a link after editing? 检查链接的文本是否为“B”,然后删除其 class? - Check whether link's text is “B” then remove its class? 当用户单击一个元素时:阻止默认操作,显示菜单,然后在单击菜单时恢复默认操作 - When the user clicks an element: Prevent default action, present menu(s), then resume default action when menu is clicked 仅当用户单击相应的链接时,才如何呈现部分内容? - How to render a partial only when a user clicks the corresponding link?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM