Solved

radGrid Cells alignment

Posted on 2010-11-10
3
3,301 Views
Last Modified: 2012-05-10
I'm using a telerik RadGrid with data dynamically created on page load...

I am formatting the text-alignment with the attached code.

Is there a faster "For each..." way of doing this?
Protected Sub grdAvailableForSale_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grdAvailableForSale.ItemDataBound
        If TypeOf e.Item Is GridHeaderItem Then
            Dim item As GridHeaderItem = DirectCast(e.Item, GridHeaderItem)
            item.Cells(3).HorizontalAlign = HorizontalAlign.Center
            item.Cells(4).HorizontalAlign = HorizontalAlign.Center
            item.Cells(5).HorizontalAlign = HorizontalAlign.Center
            item.Cells(6).HorizontalAlign = HorizontalAlign.Center
            item.Cells(7).HorizontalAlign = HorizontalAlign.Center
            item.Cells(8).HorizontalAlign = HorizontalAlign.Center
        End If
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            item.Cells(3).HorizontalAlign = HorizontalAlign.Center
            item.Cells(4).HorizontalAlign = HorizontalAlign.Center
            item.Cells(5).HorizontalAlign = HorizontalAlign.Center
            item.Cells(6).HorizontalAlign = HorizontalAlign.Center
            item.Cells(7).Text = Convert.ToDateTime(item.Cells(7).Text).ToString("MM/dd/yyyy")
            item.Cells(7).HorizontalAlign = HorizontalAlign.Center
            item.Cells(8).HorizontalAlign = HorizontalAlign.Center
        End If

Open in new window

0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 34107256
Hi,

Try to use this code for each column, not in the ItemDataBound event, but in the event where you are setting the datasource dynamically

grdAvailableForSale.Columns(3).HorizontalAlign = HorizontalAlign.Center
0
 

Accepted Solution

by:
lrbrister earned 0 total points
ID: 34111396
Actually I grunted out my own solution with the attached code
PrivateSubRadGrid1_ItemDataBound(sender AsObject, e AsGridItemEventArgs)
    IfTypeOfe.Item IsGridHeaderItem Then
        Dimitem As GridHeaderItem = TryCast(e.Item, GridHeaderItem)
        Fori AsInteger= 0 Toitem.Cells.Count - 1
            item.Cells(i).HorizontalAlign = HorizontalAlign.Center
        Next
    EndIf
 
    IfTypeOf e.Item IsGridDataItem Then
        TryCast(e.Item, GridDataItem).HorizontalAlign = HorizontalAlign.Center
    EndIf
EndSub

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 34143328
FOund my own solution
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question