This is a migrated thread and some comments may be shown as answers.

[Solved] Formatting Column - shorten length - who?

2 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grzesiek
Top achievements
Rank 2
Iron
Grzesiek asked on 24 May 2008, 11:15 PM
I have columns in RadGrid.

I one column (HyperlinkColumn) I want to short DataTextField when it is longer than 50 characters for example.

I have this code:
  If (TypeOf (e.Item) Is GridDataItem) Then 
 
            'Get the instance of the right type 
            Dim dataBoundItem As GridDataItem = e.Item 
 
            'Check the formatting condition 
            If (dataBoundItem("wydarzenie_id").Text).Length > 6 Then 
                dataBoundItem("wydarzenie_id").Text = "asd" 
                'Customize more... 
            End If 
        End If 

But it doesn't work properly (I've put this code into Rad ItemDataBound event).

Can anyone help me?

2 Answers, 1 is accepted

Sort by
0
Grzesiek
Top achievements
Rank 2
Iron
answered on 25 May 2008, 09:35 AM
This code works fine only for simply GridBoundColumn:
        'Is it a GridDataItem 
        If (TypeOf (e.Item) Is GridDataItem) Then 
            'Get the instance of the right type 
            Dim dataBoundItem As GridDataItem = e.Item 
 
            'Check the formatting condition 
            If ((dataBoundItem("wydarzenie_tytul").Text).Length > 20) Then 
                Dim size As Integer = (dataBoundItem("wydarzenie_tytul").Text).Length 
                dataBoundItem("wydarzenie_tytul").Text = dataBoundItem("wydarzenie_tytul").Text.Remove(20, size - 20) 
                dataBoundItem("wydarzenie_tytul").Text &= " (...)" 
                'Customize more... 
            End If 
        End If 

But with HyperLinkColumn, doesn't work - why?
0
Grzesiek
Top achievements
Rank 2
Iron
answered on 25 May 2008, 12:50 PM
Ok, I solved my problem, here is the code:

     If TypeOf e.Item Is GridDataItem Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
            Dim hp As HyperLink = DirectCast(item("wydarzenie_tytul").Controls(0), HyperLink) 
            'hp.NavigateUrl = ConvertCharacters(HttpUtility.HtmlDecode(hp.Text)) 
 
            hp.NavigateUrl = ConvertCharacters(HttpUtility.HtmlDecode(hp.NavigateUrl)) 
            hp.NavigateUrl = hp.NavigateUrl.Insert(hp.NavigateUrl.Length - 4, "."
            If hp.Text.Length > 20 Then 
                hp.Text = hp.Text.Remove(hp.Text.Length - 20) 
                hp.Text &= " (...)" 
            End If 
        End If 

Tags
Grid
Asked by
Grzesiek
Top achievements
Rank 2
Iron
Answers by
Grzesiek
Top achievements
Rank 2
Iron
Share this question
or