[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

DataGrid: Align Columns Right

Posted on 2004-10-29
12
Medium Priority
?
481 Views
Last Modified: 2012-05-05
Is it possible to programatically (perhaps through java script) right align columns in a datagrid control?  All of our datagrid controls are populated on the fly.
0
Comment
Question by:billy21
[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
  • 5
  • 4
  • 3
12 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 12443357
You can Set it like following:
// You need to set this before you call DataBind() method..
      DataGrid1.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Right;

-tushar
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 1600 total points
ID: 12443378
Or if you are dealing with AutoGenerated Column here. In that case you'll have to Align the columns using ItemDataBound event of datagrid.

Inside ItemDataBound of DataGrid just add one line like following..
------------------------------------------------------------------------
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
    e.Item.Cells[0].HorizontalAlign = HorizontalAlign.Right;    //for VB modify it like: e.Item.Cells(0).HorizontalAlign = HorizontalAlign.Right
}
------------------------------------------------------------------------

-tushar
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12443389
or in VB
 DataGrid1.Columns(0).ItemStyle.HorizontalAlign = HorizontalAlign.Right
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:AerosSaga
ID: 12443402
lol beat me too it tusharashah;) but here is the above in vb

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
 e.Item.Cells(0).HorizontalAlign = HorizontalAlign.Right
End Sub
0
 
LVL 6

Author Comment

by:billy21
ID: 12443496
The itemdatabound event doesn't appear to be firing.  I placed the following code in the codebehind of my page and inserted a break point.  It never breaks there and nothing happens to my column alignment...

    Private Sub grdBudget_ItemDataBound(ByVal sender As Object, ByVal e As system.Web.UI.WebControls.DataGridItemEventArgs)
        e.Item.Cells(1).HorizontalAlign = HorizontalAlign.Right
    End Sub

0
 
LVL 6

Author Comment

by:billy21
ID: 12443509
Columns are automatically generated and I use VB .Net.
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12443518
On your Design view.. Click on DataGrid then Click on "Events" in property Window.. (On top panel)

& then double click on OnItemDataBound event from the list...

Right your code inside the newly created Method..

-tushar
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12443554
Or inside your WebForm check your if you have following line in your InitializeComponent() method..
private void InitializeComponent()
{    
      this.grdBudget.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.grdBudget_ItemDataBound);
      this.Load += new System.EventHandler(this.Page_Load);
}

-tushar
0
 
LVL 6

Author Comment

by:billy21
ID: 12443566
There is no 'Events' property for the datagrid in my list of properties...
EdititemIndex
EditItemStyle
Enabled
EnableViewState
0
 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 400 total points
ID: 12443576
Look in the codebehind view for the drop downs
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12443580
control---------------                                                                    event------------------------------
--------------------------------------------------------------------------------------------------------------------------
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12443595
your in design view, go to codebehind
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

650 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