DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Fetch Hyperlinkfield Value On Rowbound Event

01.31.2012
| 4159 views |
  • submit to reddit
        Add following as column to your grid view

<asp:HyperLinkField DataTextField="Employee" HeaderText="Employee Name"                                                                         DataNavigateUrlFields="Employee" DataNavigateUrlFormatString="~/AddEMP.aspx?EMP={0}" />

Write following code on rowcommand event 
HyperLink hyp = (HyperLink)Gridview1.Rows[Gridview1Row.RowIndex].Cells[columnEmployeeIndex].Controls[0];
emp = string.IsNullOrWhiteSpace(hyp.Text) ? 0 : Convert.ToInt32(hyp.Text);