Aaron
Aaron

Reputation: 57778

Can't access HyperLinkField text in a GridView

I have a HyperLinkField defined as follows:

<asp:GridView ID="gvNotifications" runat="Server" AutoGenerateColumns="false" EnableViewState="true" CssClass="tableWhole" AlternatingRowStyle-CssClass="tableAlt">
<Columns>
    <asp:HyperLinkField HeaderText="Item#" DataTextField="sku" 
                        DataNavigateUrlFormatString="/store/item/{0}/"
                        DataNavigateUrlFields="sku" ItemStyle-CssClass="itemNo" />

In my code-behind, I'm attempting to access the Text property like this:

    For Each gvRow In gvNotifications.Rows
        processItem(gvRow.Cells(0).Text.ToString)
    Next

This code worked when it was defined as a BoundField, like this:

<asp:BoundField HeaderText="Item #" DataField="sku" ItemStyle-CssClass="itemNo" />

How can I access the Text property on a HyperLinkField in a GridView.Row.Cells?

Upvotes: 0

Views: 1247

Answers (1)

Aaron
Aaron

Reputation: 57778

Nevermind, I figured it out based-on a related C# question.

For Each gvRow In gvNotifications.Rows
    processItem(gvRow.Cells(0).Controls(0).Text.ToString)
Next

Upvotes: 2

Related Questions