Solved

radGrid Cells alignment

Posted on 2010-11-10
3
3,211 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now