Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 4-Sep-11 18:13pm
v2

//C# code i dont know in vb . plz understand///
//in row data bound of grid view
C#
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 for opening popup
JavaScript
<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>
 
Share this answer
 
v3
Hi you can easily do it using GridView Template Field.
XML
<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
                }
            }
        }



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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900