Skip to main content

Getting the text of a GridView HyperLink Bound Field

It's quite common to do some extra processing of data during a GridView's Row_DataBound event. You can normally capture the value of the GridView cell like this, which would capture the value of the 3rd column in the grid (row count is 0 based). 

If e.Row.RowType = DataControlRowType.DataRow Then

    Dim Value as String = CType(e.row.cells(2).Text, String)

    'some manipulation of cell data, such as formatting, etc.

    e.row.cells(2).Text = NewValue

End If

This works well if the field is configured as a BoundField: 

<asp:BoundField DataField="DataBaseFieldValue" HeaderText="Field Name" />

But if the field is configured like this, as a HyperLink field, then you must get to its value differently:

<asp:HyperLinkField DataTextField="Symbol" HeaderText="Symbol" DataNavigateUrlFields="StockID"  DataNavigateUrlFormatString="EditStock.aspx?id={0}&ref=pp" SortExpression="s.symbol" />

This assumes that the field you're looking for is the first column of the GridView control. 

If e.Row.RowType = DataControlRowType.DataRow Then

    Dim HyperLinkText as String = DirectCast(e.Row.Cells(0).Controls(0), HyperLink).Text

    Dim HypLinkURL as string = DirectCast(e.Row.Cells(0).Controls(0), HyperLink).NavigateUrl

    'Do something with the values

End If

Comments

Popular posts from this blog

California: A Model for the Rest of the Country, Part 2

Part 1 here . On Leaving the Golden State Guest Post by NicklethroweR . Posted on the Burning Platform. The fabled Ventura Highway is all that separates my artist loft from the beach where surfing first came to the United States. Both my balcony and front patio face the freeway at about eye level and I could easily smack a tennis ball right on to the ever busy 101. Access to the beach and boardwalk is very important to a Tourist Town such as mine and I can see one underpass from my balcony and another underpass from the patio. Further up the street are two pedestrian bridges. Both have been recently remodeled so that people can not use it to kill themselves by leaping down into traffic. The traffic, just like the spice, must flow and the elites that live here do not like to be inconvenienced as they dart about between Malibu and Santa Barbara. Another feature of living where I live would have to be the homeless, the insane and the drug addicts that wander this particular...

Top Five Consumer Cyber Security FAQs

Business, technology, environmental and economic changes are a part of life, and they are coming faster all the time. All of these changes and advancements can be distracting and make us more vulnerable to cyber scams. That's why protecting your credit is a critical part of protecting yourself from cyber security threats. Security researchers have reported that hackers and scammers are using any opportunity or vulnerability to target both individuals and companies. You may have already seen these attempts in the form of fake emails or calls. Here are the top five questions Equifax ®  has received about how individuals can protect themselves from cyber security threats and help to improve your credit protection. 1. How can I better protect my credit? Check your credit reports frequently. You can get free credit reports from the nationwide credit reporting agencies (Equifax, Experian ®  and TransUnion ® ) at annualcreditreport.com. Check your credit reports frequently to closely...

School Choice Passed by Texas Senate

The Texas Senate on Thursday approved a $500 million school choice bill mostly along party lines after hours of passionate debate. It will now head for consideration in the House, where members rejected similar proposals during the regular session. Senators passed Senate Bill 1 by a 18-13 vote, with one Republican joining all Democrats in voting against the measure. The bill will likely face steep resistance in the House, where Democratic members and many rural Republicans have vehemently opposed such proposals. School choice programs, also called education savings accounts or vouchers, use public money to help pay for a child’s private schooling. “We must recognize that a one-size-fits-all approach doesn't fit the needs of our diverse student population,” said Sen. Brandon Creighton, R-Conroe, who authored SB 1 and estimated the proposal could serve about 60,000 students. Texas has about 5.5 million children in public schools. Public schools have failed the American people, especi...