.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to get value of hyperlinkfield

Posted By:shankey       Posted Date: July 26, 2011    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

this article helps to understand how to get value of hyperlinkfiled.

Hi All,

This article will help you to understand how to get  value of the hyperlinkfield in gridview.

For example we have following hyperlinkfield in the grid view.

<asp:HyperLinkField DataTextField="StudentName" HeaderText="Student Name" HeaderStyle-Width="110px"
" DataNavigateUrlFormatString="~/AddStudentName.aspx?StudentName={0}" />

We need to get the value of this field on row command.
Then we can achieve this as shown below:
HyperLink hypStudentName = (HyperLink)Gv.Rows[gvRow.RowIndex].Cells[columnStudentNameIndex].Controls[0];
ViewStateStudentName = string.IsNullOrWhiteSpace(hypStudentName.Text) ? 0 : Convert.ToInt32(hypStudentName.Text);

You need to get the control from the cell of hyperlinkfield and cast it to hyperlink and then you can get the text i.e. the value of the field by getting text of the hyperlink control. As shown above.


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend