Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have working with GridView. I need to set a hyperlink for entire row, i have develop that one. But whenever click on SName only I got the next page rest of the columns I don't have link. The following code I have used.

Design

XML
<asp:GridView ID="GridView1" runat="server">

<asp:TemplateField HeaderText="SName"
<ItemTemplate>
<a href='<%#"StuDetails.aspx?Id="+DataBinder.Eval(Container.DataItem,"Id") %>' target="_blank">
<%#Eval("SName")%>
</a>
</ItemTemplate>
</TemplateFiled>

<asp:BoundField DataField="SName" HeaderText="Student Name" />
<asp:BoundField DataField="SMarks" HeaderText="Student Marks" />
<asp:BoundField DataField="SDOB" HeaderText="Student DOB" />




C# Code:

C#
protected void GridView1_RowCreated1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.className='mouseover'");
            e.Row.Attributes.Add("onmouseout", "this.className='mouseout'");

            e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);

        }
    }



Note:

How to use "~/StuDetails.aspx?Id="+DataBinder.Eval(Container.DataItem,"Id") target="_blank" in place "Select$"

Thanks in advance.
Posted
Comments
Prasad Avunoori 10-Sep-14 1:17am    
You had given hyperlink to SName only, how can you expect it for all columns?
Member 10021658 10-Sep-14 1:32am    
Thanks for your reply. I understand what you told, but whenever placed on empty spaces of the row its don't have link. Is there any possibility for without using TemplateFiled how can set the hyperlink.

Replace all your BoundFields with TemplateFiela as you did for SName.
 
Share this answer
 
Comments
Member 10021658 10-Sep-14 1:34am    
Thanks for your reply. Whenever replace all BoundFields of rest of columns, the link shows only the respcted column. But I need to entire row where you placed mouse in row at anywhere not only columns. Is there any possibility for without using TemplateFiled how can set the hyperlink.
 
Share this answer
 
Comments
Member 10021658 10-Sep-14 2:36am    
Thanks for your reply. Its working without errors, but the link show up to end of the column text
, I don't want to such type. I need Entire row where you are placed the mouse. Please checkout your side output properly.
Member 10021658 10-Sep-14 4:53am    
Santhosh please help me.

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