Jeff
Jeff

Reputation: 449

How to make a hyperlinkfield in asp.net c# read only?

I need to enable a link that shows a .pdf document based on a parameter that comes from the datanavigateurlfield thats located in a folder in my project. I want to make the hyperlink "read only" or have it navigate back to the default webpage or even show a messagebox if there is no report in the folder for a specific cell a user clicks on in the gridview. Is this possible? Thanks.

Upvotes: 1

Views: 1008

Answers (2)

SeanCocteau
SeanCocteau

Reputation: 1876

It sounds like you need to qualify the location that the link navigates to rather than anything fancy - in other words, perform this validation server-side.

For example, capture the DataRowBound (or equilivalent) event of your datagrid / container. Obtain the dataitem and determine whether the URL is correct. If it is and there's nothing to see here. If it isn't, change the navigateUrl of the field to the appropriate location or JS code.

Upvotes: 0

IUnknown
IUnknown

Reputation: 22468

Use TemplateField instead of HyperLinkField:

<asp:TemplateField >
     <ItemTemplate>
          <asp:HyperLink runat="server" Text='<%# Eval("Name") %>'
               NavigateUrl='<%# String.IsNullOrEmpty((String)Eval("Url"))? "javascript: alert(\"no report\"); return false;" : Eval("Url") %>' />
     </ItemTemplate>
</asp:TemplateField>

Upvotes: 1

Related Questions