如何使我的整个gridview行具有超链接 [英] How to make my entire gridview row to have hyperlink

查看:91
本文介绍了如何使我的整个gridview行具有超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使我的整个gridview行都具有超链接-因此基本上在鼠标悬停时,我要有一个光标指针并在我的gridview行上突出显示.然后单击,我想调用另一个页面(summary.aspx?id = 1245)-该ID应该在该行的第0列中获取.

我正在为我的gridview使用模板字段.如果可能的话,请在VB.NET代码中向我展示.

谢谢.

I want to make my entire gridview row to have hyperlink - so basically on mouse over I want to have a cursor hand and highlights on my gridview row. then on click I want to call my another page (summary.aspx?id=1245) - the id should be get in column 0 of the row.

I am using a template field for my gridview. If possible kindly show me in VB.NET code.

Thanks.

推荐答案

//我在vb中不知道的C#代码.请了解///
//在网格视图的行数据范围内
//C# code i dont know in vb . plz understand///
//in row data bound of grid view
if (e.Row.RowType == DataControlRowType.DataRow)
                {                   
                    e.Row.Attributes.Add("onMouseOver", "this.style.cursor = 'hand';this.style.backgroundColor = 'yellow';");
                    e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor = 'white';");
                    DataControlFieldCell cid = (DataControlFieldCell)(id from grid view element );                  
                    string path = "summary.aspx?id="+cid.Text;
                    e.Row.Attributes["onclick"] = " return SelectedObjRptPopUp('" + path + "')";
                }



//用于打开弹出窗口的javascript



//javascript for opening popup

<script type="text/javascript">
   function SelectedObjRptPopUp(url)
    {
         
    var popupStyle = "dialogheight=500px;dialogwidth=835px;dialogleft:200px;dialogtop:200px;status:no;help:no;";
    var var1 = window.showModalDialog(url, '', popupStyle);
    }
    </script>


您好,您可以使用GridView模板字段轻松地做到这一点.
Hi you can easily do it using GridView Template Field.
<asp:TemplateField>
             <HeaderTemplate>
               Link
             </HeaderTemplate>
             <ItemTemplate>
                 <asp:LinkButton PostBackUrl='<%# Eval("Value" )%>' Text='<%# Eval("Value" )%>'

                       ID="lnk" runat="server" />
             </ItemTemplate>
         </asp:TemplateField>



在何处重视您要放置的链接.您也可以从后面的代码中执行相同的操作.



Where value the link that you want to put. You can do the same from code behind as well.

protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Customer cust = e.Row.DataItem as Customer;
                if (!cust.ShowURL)
                {
                    LinkButton lnkWebURL = e.Row.FindControl("lnk") as LinkButton;
//                    Set lnkWebURL stugg
                }
            }
        }




仅供参考,这是代码项目-常见问题系列1:ASP.Net GridView [ ^ ]
您也可以在那找到相同的内容.




FYI, Here is the list of Code Project - Frequently Asked Questions Series 1: The ASP.Net GridView[^]
You can find the same over there as well.


这篇关于如何使我的整个gridview行具有超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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