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

Custom Formatting

4 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mansi A.
Top achievements
Rank 1
Mansi A. asked on 28 Nov 2011, 07:44 PM
Hi,
I'm trying to implement some custom formatting on RadGrid I used code like be below :

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemDataBound
         If (TypeOf e.Item Is GridDataItem) Then
             Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
             If (dataItem("Country").Text = "Mexico") Then
                dataItem.CssClass = "MyMexicoRowClass"
             End If
         End If
End Sub

But e.item is GridPagerItem there for rest of code is not accessible. Anythough?
basically I want to check value of column and depend on it I want to change background to different color for the rows
i'm using radgrid paging allowed and CSS

RadGrid populated programmatically .
Newbie,
MM

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 29 Nov 2011, 05:50 AM
Hello Mansi Mansi,

To format the GridPagerItem you just have to write more conditional statements in the ItemDataBound as shown below:
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemDataBound
         If (TypeOf e.Item Is GridDataItem) Then
             Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
             If (dataItem("Country").Text = "Mexico") Then
                dataItem.CssClass = "MyMexicoRowClass"
             End If
         End If
         If TypeOf e.Item Is GridPagerItem Then
               Dim pager As GridPagerItem = CType(e.Item, GridPagerItem)
                'apply formatting here  
            End If
  
End Sub

Best wishes,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Mansi A.
Top achievements
Rank 1
answered on 29 Nov 2011, 07:09 AM
sorry maybe i was not clear i don't want to format pager
my code like this for some reason (this is my problem) e.item return GridPagerItem instead of GridDataItem in the code when i try to debug it skip the the first if condition. My Question is what is wrong or could be set wrongly that causing e.item is GridPagerItem not GridDataItem?
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemDataBound
         If (TypeOf e.Item Is GridDataItem) Then
             Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
             If (dataItem("Country").Text = "Mexico") Then
                dataItem.CssClass = "MyMexicoRowClass"
             End If
         End If
end sub

Thanks Again
0
Pavlina
Telerik team
answered on 29 Nov 2011, 09:55 AM
Hi Mansi Mansi,

Generally, all items that show data are of type GridDataItem (browse mode) and GridEditFormItem, if an item is in edit mode - EditForms. In order to fetch the needed data you should check the event parameter e.Item if it is of the corresponding type(GridCommandItem / GridPagerItem / GridDataItem etc). Then you can access a cell corresponding to a certain column using the column's UniqueName. You can learn more about this in the online resources below:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

I am also attaching a sample project which demonstrates formatting of GridDataItem.

I hope this helps.

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Pavlina
Telerik team
answered on 29 Nov 2011, 09:59 AM
Hello Mansi Mansi,

I am attaching the mentioned project here.

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Mansi A.
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Mansi A.
Top achievements
Rank 1
Share this question
or