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

[Solved] ItemDataBound hitting every 2nd row?

2 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ciaran
Top achievements
Rank 1
Ciaran asked on 30 Sep 2009, 02:55 PM
Hey , I'm looping through a heairarchichal rad grid with 1 lkinkbutton in each section
I'm checking if the length is over a ceratin number and if it is, shorten it and add a tooltip....fairly standard stuff

 Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound 
 
        If e.Item.ItemType = GridItemType.Item Then 
 
            Dim linkbutton1 As LinkButton = e.Item.FindControl("linkbutton1") 
            If linkbutton1 Is Nothing Then 
            Else 
 
                If linkbutton1.Text.Length > 30 Then 
 
                    linkbutton1linkbutton1.ToolTip = linkbutton1.Text 
                    linkbutton1linkbutton1.Text = linkbutton1.Text.Substring(0, 40) + "..." 
                End If 
            End If 
 
            Dim linkbutton2 As LinkButton = e.Item.FindControl("linkbutton2") 
            If linkbutton2 Is Nothing Then 
            Else 
 
                If linkbutton2.Text.Length > 30 Then 
 
                    linkbutton2linkbutton2.ToolTip = linkbutton2.Text 
                    linkbutton2linkbutton2.Text = linkbutton2.Text.Substring(0, 40) + "..." 
                End If 
            End If 
 
            Dim linkbutton3 As LinkButton = e.Item.FindControl("linkbutton3") 
            If linkbutton3 Is Nothing Then 
            Else 
 
                If linkbutton3.Text.Length > 30 Then 
 
                    linkbutton3linkbutton3.ToolTip = linkbutton3.Text 
                    linkbutton3linkbutton3.Text = linkbutton3.Text.Substring(0, 40) + "..." 
                End If 
            End If 
 
        End If 
 
    End Sub 

for some reason , the code only hits every 2nd row in each of the grids !

any ideas?

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Oct 2009, 08:52 AM
Hello Ciaran,

The ItemType attribute of an item is used to differentiate between the normal rows(odd rows) of a grid and alternating rows(even rows) of the grid. Hence, if you want to clip the text of the linkbuttons for all the rows in the grid, you can rewrite the following line of your code
If e.Item.ItemType = GridItemType.Item Then 

with the following code instead and check if it helps:
If TypeOf e.Item Is GridDataItem Then  

Thanks
Princy.
0
Ciaran
Top achievements
Rank 1
answered on 01 Oct 2009, 09:03 AM
Thats really helpful, thanks
Tags
Grid
Asked by
Ciaran
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ciaran
Top achievements
Rank 1
Share this question
or