Professional Web Applications Themes

HyperLinkColumn and column width - ASP.NET Data Grid Control

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?LineIt emId={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 ...

  1. #1

    Default HyperLinkColumn and column width

    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?LineIt emId={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 Guest

  2. #2

    Default Re: HyperLinkColumn and column width

    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("ProcessLineIte mId"))
    %>
    </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:
    [url]http://aspnet.4guysfromrolla.com/articles/100202-1.aspx[/url]

    hth


    Scott Mitchell
    [email]mitchell4guysfromrolla.com[/email]
    [url]http://www.4GuysFromRolla.com[/url]
    [url]http://www.ASPFAQs.com[/url]
    [url]http://www.ASPMessageboard.com[/url]

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


    [email]matifhotmail.com[/email] (Atif Jalal) wrote in message news:<b7af12d4.0402050643.5385bdposting.google.co m>...
    > 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?LineIt emId={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 Guest

Similar Threads

  1. Column Width
    By Justin in forum ASP.NET Data Grid Control
    Replies: 5
    Last Post: December 22nd, 07:21 AM
  2. DataGrid Column Width
    By frank in forum ASP.NET Data Grid Control
    Replies: 9
    Last Post: March 21st, 04:07 PM
  3. DG Column Width vs Table Column Width
    By Carl Howarth in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: October 24th, 08:48 AM
  4. how to set datagrid column width ?
    By Sam in forum ASP.NET Data Grid Control
    Replies: 15
    Last Post: May 3rd, 08:35 AM
  5. Fix the Column width of a DataGrid
    By Raja in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 18th, 06:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139