HyperLinkColumn and column width

Discussion in 'ASP .Net Datagrid Control' started by Atif Jalal, Feb 5, 2004.

  1. Atif Jalal

    Atif Jalal Guest

    I am using a Datagrid control and one of its column is a
    'HyperLinkColumn'. The link text for this HyperLinkColumn is sometimes
    beyond 100 characters. I would like to display the link on multi-line
    if the number of characters in the link exceed 100 characters. I tried
    adding the <ItemStyle> to the HyperLinkColumn tag but it did not
    work, the whole of the link is displayed on one line with the column
    width getting extended.

    <asp:HyperLinkColumn
    DataNavigateUrlFormatString="'LineItem.aspx?LineItemId={0}&Process=1&'"
    DataNavigateUrlField="ProcessLineItemId" DataTextField="Description"
    HeaderText="Line Item - Description">

    <ItemStyle Width="100px" Wrap=True></ItemStyle>

    </asp:HyperLinkColumn>

    Is it that <ItemStyle> does not work with <asp:HyperLinkColumn> ? Any
    help appreciated.
    Atif Jalal, Feb 5, 2004
    #1
    1. Advertising

  2. Atif Jalal

    Scott Guest

    Atif, the HyperLinkColumn does not provide any property to limit the
    number of characters. You will either have to:

    (a) Use a TemplateColumn, calling some custom function to limit the
    length. That is, you might have:

    <asp:TemplateColumn>
    <ItemTemplate>
    <%# TruncateURL(DataBinder.Eval(Container.DataItem,
    "Description"), DataBinder.Eval(Container.DataItem("ProcessLineItemId"))
    %>
    </ItemTemplate>
    </asp:TemplateColumn>

    And then create a method in your code-behind class like:

    Protected Function TruncateURL(desc as String, lineItemID as Integer)
    as String
    If desc.Length > 100 then
    desc = desc.Substring(0, 95) & "..."
    End If

    Return "<a href=""LineItem.aspx?LineItemId=" & lineItemID &
    "&Process=1"">" & desc & "</a>"
    End Function


    (b) Create a custom DataGridColumn class that can limit the number of
    characters based on some property. There is an example of such a
    class at:
    http://aspnet.4guysfromrolla.com/articles/100202-1.aspx

    hth


    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!


    (Atif Jalal) wrote in message news:<>...
    > I am using a Datagrid control and one of its column is a
    > 'HyperLinkColumn'. The link text for this HyperLinkColumn is sometimes
    > beyond 100 characters. I would like to display the link on multi-line
    > if the number of characters in the link exceed 100 characters. I tried
    > adding the <ItemStyle> to the HyperLinkColumn tag but it did not
    > work, the whole of the link is displayed on one line with the column
    > width getting extended.
    >
    > <asp:HyperLinkColumn
    > DataNavigateUrlFormatString="'LineItem.aspx?LineItemId={0}&Process=1&'"
    > DataNavigateUrlField="ProcessLineItemId" DataTextField="Description"
    > HeaderText="Line Item - Description">
    >
    > <ItemStyle Width="100px" Wrap=True></ItemStyle>
    >
    > </asp:HyperLinkColumn>
    >
    > Is it that <ItemStyle> does not work with <asp:HyperLinkColumn> ? Any
    > help appreciated.
    Scott, Feb 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Atif Jalal

    HyperLinkColumn and column width

    Atif Jalal, Feb 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    899
    Atif Jalal
    Feb 5, 2004
  2. AndrewF
    Replies:
    1
    Views:
    762
    Bruce Barker
    Oct 10, 2005
  3. ssk
    Replies:
    5
    Views:
    5,492
    Jukka K. Korpela
    Oct 30, 2006
  4. David Basford
    Replies:
    3
    Views:
    2,416
    BootNic
    Sep 30, 2007
  5. Carl Howarth

    DG Column Width vs Table Column Width

    Carl Howarth, Oct 22, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    263
    Eliyahu Goldin
    Oct 24, 2004
Loading...

Share This Page