如何通过数据库在网格视图中使用onclick功能 [英] How to use onclick functionality in grid view through database

查看:66
本文介绍了如何通过数据库在网格视图中使用onclick功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在逐步查看网格视图问题,我正在尝试将一个href链接与一个onclick = function()发送到gridview.That因为HTML代码在gridview中显示而不是显示超级链接,所以无法正常工作。



我想通过这个超级链接调用javascript函数。



所以,如果任何人有任何解决方案而不是回复。



谢谢和问候,

vinod

解决方案

你可以这样做。



Html Anchor



参考 - http://stackoverflow.com/a/2942811 [ ^ ]。

引用:

我发现的解决方案是使用asp:TemplateField这样,不会丢失排序功能并使用Eval使用datatextfield:

< PR e lang =HTML> < asp:TemplateField HeaderText = 名称 SortExpression = PartnerName >
< ItemTemplate >
< < span class =code-leadattribute> a onclick = javascript:alert('ok') href = http:// <% #Eval( PartnerName)%> > < % #Eval( PartnerName)%> < / a >
< / ItemTemplate >
< / asp:TemplateField >



Asp HyperLink



参考 - 通过onclick将网格视图变量传递给javascript弹出窗口[ ^ ]。

Quote:

I测试它,以下一个适用于我:



 <   asp:TemplateField  >  
< ItemTemplate >
< asp:HyperLink ID = HyperLink1 runat = server NavigateUrl = < span class =code-keyword> <% String .Format( javascript:void(window.open('http:// www。{0} .com')),Eval ( ProductID))% > ; > HyperLink < / asp:HyperLink >
< / ItemTemplate >
< / asp:TemplateField >


Hi All,

I am phasing issue with grid view,I am trying to send one href link with one onclick = function() to the gridview.That is not working because HTML code displaying as it is in gridview instead of showing hyper link.

I want to call javascript function through this hyper link.

So please if any one have any solution than reply.

Thanks and regards,
vinod

解决方案

You can do like below.

Html Anchor

Refer - http://stackoverflow.com/a/2942811[^].

Quote:

The solution I found was using asp:TemplateField this way, without losing the Sorting ability and using the datatextfield using Eval:

<asp:TemplateField HeaderText="Name" SortExpression="PartnerName">
    <ItemTemplate>
        <a onclick="javascript:alert('ok')" href="http://<%#Eval("PartnerName")%>"><%#Eval("PartnerName")%></a>
    </ItemTemplate>
</asp:TemplateField>


Asp HyperLink

Refer - Passing gridview variables to javascript popup through "onclick"[^].

Quote:

I test it and this following one works for me:

<asp:TemplateField>
     <ItemTemplate>
          <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=<%# String.Format("javascript:void(window.open('http://www.{0}.com'))", Eval("ProductID")) %>> HyperLink</asp:HyperLink>
      </ItemTemplate>
</asp:TemplateField>


这篇关于如何通过数据库在网格视图中使用onclick功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆