ASP. NET 2.0-use the hyperlinkfield data row of the gridview control to establish cnblogs)

Source: Internet
Author: User
Use the hyperlinkfield data row of the gridview Control

Make good useGridviewControlHyperlinkfieldData row

 

With the helpGridviewControlHyperlinkfieldData row, we canGridviewDisplay a hyperlink for each data column in the control, allowing users to easily redirect to a specific target location (location in a specific webpage or webpage ).

 

In useHyperlinkfieldWhen running data, you must first consider the text on the hyperlink. You can describe the following two conditions:

 

QIf you want the hyperlink of each data column to display the same fixed textHyperlinkfieldTheTextSet the attribute to the required text. Chart1This is an example.

 

 

Chart1

 

QIf you want to use the content of a field as the hyperlink of each data columnHyperlinkfieldTheDatatextfieldSet the attribute to this field. Chart2This is an example.

Of courseDatatextfieldAttribute combination is similarDatatextformatstringAttribute. We often useDatatextformatstringAttribute to formatDatatextfieldThe data value of the field specified by the attribute. Chart3This is an example.

 

 

Chart2

 

 

Chart3

 

Learn how to setHyperlinkfieldAfter the text of the hyperlink generated by the Data row is learned, the next step is to set the hyperlink goal.URL. If you want to link all hyperlinks to the sameURL, Please directlyNavigateurlSet the property to the requiredURL. Although this setting is the most simple, it is also very impractical. After all, even if it is linked to the same web page, each data column is linked to different locations in the same web page (that is, bookmarks ). -Bookmark). Therefore, what is more practical isDatanavigateurlfieldsAttribute, the reason is very simple. It allows you to specifyURLAs the destination of the Link (Note that the attribute name isSAt the end, there is a mystery. I will explain it later.). As a chart4As shown in「 URL 」FieldURLAs the destination of the link, different superlinks will have their ownURL.

 

Chart4

 

Of courseDatanavigateurlfieldsAttribute, never forget its good brother - DatanavigateurlformatstringAttribute.DatanavigateurlformatstringThe main purpose of a property is to format a hyperlink.URL. For example, assume that you assignDatanavigateurlfieldsThe attribute fields are not complete.URL(For example:Http://www.gotop.com.twIs only the name of the webpage file (for example:Alexpage. aspx), If you want the hyperlinkURLIf you can add a complete path before the webpage file name, you can write the following code:

 

<Asp: hyperlinkfield datanavigateurlfields = "personal webpage"
Datanavigateurlformatstring = "~ /Members/{0 }"
Headertext = "personal webpage" text = "view personal webpage"/>

 

In the preceding statementRoot directoryBottomMembersWebpage files in the data folder. In terms of the following statement, it means to link to an absoluteURL(That is, a website)MembersWebpage files in the data folder:

 

<Asp: hyperlinkfield
Datanavigateurlfields = "personal webpage"
Datanavigateurlformatstring = "http://www.alexmember.com/members/4100 }"
Headertext = "personal webpage" text = "view personal webpage"/>

 

Speaking of this, I believe everyone is rightHyperlinkfieldData lines are ready for use. Now, we need to look back and studyDatanavigateurlfieldsAttribute, why is its name specialSWhat about the end? The reason is simple, because you can assign more than one field nameDatanavigateurlfieldsAttribute. When do we need to do this? For exampleURLTo link to the same web page, but to pass the query string to the web page (similar to the following), so that the target web page can be processed according to different parameter values, you need to do this:

 

Memberpage. aspx? Name = Zhang Limin & memberlevel =

 

To make your hyperlink haveURL, You must useDatanavigateurlfieldsAttribute. At this time, you mustNameAndMemberlevelFields are also assignedDatanavigateurlfieldsProperty (NameAndMemberlevelFields must be separated by commas (,).DatanavigateurlformatstringAttribute to format it. The statement is as follows:

 

Asp : hyperlinkfield
datanavigateurlfields = "name, memberlevel "
datanavigateurlformatstring = "memberpage. aspx? Name = {0} & memberlevel = {1} "
headertext = " member webpage " text = " View member webpages " />

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.