Share via


ItemsAsLinks Property

Sets or returns whether or not the items in the list are to be treated as hyperlinks. The default value is false.

public bool ItemsAsLinks {
   get,
   set
}

Remarks

If the value of this property is true, the value of the DataTextField property is used to display the text of the hyperlink, and the DataValueField property is used to specify the target URL. Command events will not be generated for these links. Thus, when the ItemsAsLinks property is set to true, an OnItemCommand method will not be called because a new page will be loaded through an HTTP call.

Example

The following example demonstrates how to use the ItemsAsLinks property to render the list items as links. The Navigation class used in this example is a container for the name and URL of a Web link.

Public class Navigation

    Dim _siteName, _siteURL As String
    
    Public Sub New(siteName As String, siteURL As String)
        _siteName = siteName
        _siteURL = siteURL
    End Sub
    Public Property SiteName   
        Set
            _siteName = value
        End Set
       
        Get
            return _siteName
        End Get
        
    End Property
    
    Public Property SiteURL
       Set
           _siteURL = value
       End Set
       
       Get 
           return _siteURL
       End Get
       
    End Property

End Class

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
If Not IsPostBack Then
   
   List1.DataTextField = "SiteName"
   List1.DataValueField = "SiteURL"
   Dim arr As New ArrayList()
   arr.Add(New Navigation("Travel Site", "http://www.margiestravel.com"))
   arr.Add(New Navigation("Home Site", "https://www.microsoft.com"))
   List1.DataSource = arr
   List1.ItemsAsLinks = True
   List1.DataBind()
   
End If

End Sub

[C#]

Public class Navigation
{
   private String _siteName, siteURL;
   public Navigation(String siteName, String siteURL)
   {
      _siteName = siteName;
      _siteURL = siteURL;
   }
   public String SiteName { get { return _siteName; } }
   public String SiteURL ( get ( return _siteURL; ) )
}

public void Page_Load(Object sender, EventArgs e)
{
   if (!IsPostBack)
   { 
      List1.DataTextField="SiteName";
      List1.DataValueField="SiteURL";
      ArrayList arr = new ArrayList();
      arr.Add (new Navigation ("Travel Site", 
                               "http://www.margiestravel.com"));
      arr.Add (new Navigation ("Home Site",
                               "https://www.microsoft.com"));
      List1.DataSource = arr;
      List1.ItemsAsLinks = true;
      List1.DataBind ();
   }
}  

See Also

Applies to: List Class