Click here to Skip to main content
15,915,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

I have retrieved records from database to GridView, I need to set a hyperlink for entire row in gridview. But I have tried bellow format it has working with only one column, please any one help me.


<asp:GridView ID="GridView1" runat="server">
<columns><asp:TemplateField HeaderText="SName"
<itemtemplate>

<%#Eval("SName")%>



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

 
Share this answer
 
Comments
Member 10021658 9-Sep-14 7:48am    
Thanks for your reply. How to set this path like StuDetails.aspx?Id="+DataBinder.Eval(Container.DataItem,"Id"), because of I have to see the details in next page only in place of
e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);

Thanks in advance.
 
Share this answer
 
v2
Comments
Member 10021658 9-Sep-14 7:52am    
Thanks for your reply. How to set this path like StuDetails.aspx?Id="+DataBinder.Eval(Container.DataItem,"Id"), because of I have to see the details in next page only in place of
e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);

Thanks in advance.
Member 10021658 9-Sep-14 8:38am    
Please please help me.
Magic Wonder 9-Sep-14 8:42am    
Check updated solution.
Member 10021658 10-Sep-14 0:15am    
In place of "Select$", how can i use "~/StuDetails.aspx?Id="+DataBinder.Eval(Container.DataItem,"Id"). I have to navigate the entire row in next page only.
Perhaps you can add a LinkButton to each column of the GridView control.

Markup

ASP.NET
<asp:gridview id="GridView" xmlns:asp="#unknown">
   Font-Names="Arial" Font-Size="0.75em"
   CellPadding="5" CellSpacing="0"
   ForeColor="#333" AutoGenerateColumns="true"
   onrowdatabound="GridView_RowDataBound"
   runat="server">

   <HeaderStyle BackColor="#989898" ForeColor="white" />

 </asp:gridview>


Later bind it with each row.

C#
protected void GridView_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
 {

     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         LinkButton lb = new LinkButton();
         lb.ID = "lbBooks";
         lb.Text = "Select";

         e.Row.Cells[3].Controls.Add(lb);
     }
 }



You can go through this article, might help.

Programmatically add LinkButton to a GridView
 
Share this answer
 
Comments
Member 10021658 9-Sep-14 7:29am    
Thanks for your reply. But I need to working with hyperlink only. And when ever place onmouseover
to display the cursor like hand symbol only not arrow.
Member 10021658 9-Sep-14 7:56am    
onmouseover i got the hand symbol.

cursor=pointer; but I didn't get the like for entire row. I got the link on SName only.

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