473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

right aligning values in datagrid column

I'm creating a datasource and populating a datagrid at runtime. The
code is as follows:

dt = New DataTable

dt.Columns.Add(New DataColumn("Item", GetType(String)))
dt.Columns.Add(New DataColumn("Value", GetType(String)))

For i = 0 To j - 1
dr = dt.NewRow()
dr(0) = (i + 1) & "."
dr(1) = (SomeArray(i).Amount).ToString("c")

dt.Rows.Add(dr)
Next

Question: The second column contains $ amount and I need to right align
the values in that column. How do I do it?

thanks a lot

Nov 19 '05 #1
1 3982
Nemo,

Is the code you're showing for the datagrid?

It looks like it's just the datasource's code...

Right alignment would be done in the grid itself.

Instead of letting the grid autogenerate the columns you'll need to declare
each column yourself and tell it what to bind to.

Your finished grid would look something like this:

<asp:datagrid id="DataGrid1" runat="server" autogeneratecolumns="False"
width="100%">
<Columns>
<asp:BoundColumn DataField="Item" HeaderText="Item
Column"></asp:BoundColumn>
<asp:BoundColumn DataField="Value" HeaderText="Value Column"
ItemStyle-HorizontalAlign="Right"></asp:BoundColumn>
</Columns>
</asp:datagrid>

Note that the DataField is the column name to bind to in the datasource and
the autogeneratecolumns is set to false.
It's the BoundColumn's ItemStyle that lets you set horizontal alignment (And
many others).

In your codebehind you bind to the grid the same way.

DataGrid1.DataSource = [Your DataSource Here]
DataGrid1.DataBind()
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"nemo" <pa*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I'm creating a datasource and populating a datagrid at runtime. The
code is as follows:

dt = New DataTable

dt.Columns.Add(New DataColumn("Item", GetType(String)))
dt.Columns.Add(New DataColumn("Value", GetType(String)))

For i = 0 To j - 1
dr = dt.NewRow()
dr(0) = (i + 1) & "."
dr(1) = (SomeArray(i).Amount).ToString("c")

dt.Rows.Add(dr)
Next

Question: The second column contains $ amount and I need to right align
the values in that column. How do I do it?

thanks a lot

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Derek | last post by:
Another DGrid question... I can not access the values of a cell in a datagrid unless I make them visible. I do not want these fields displayed. I only want to use the values to run a stored...
3
by: Spondishy | last post by:
OK... After a previous post, I've decided that the site layout will be two columns The layout will be: 1) Page 100% wide 2) Right column will be fixed 150px, left column will use the rest...
2
by: Balamurukan | last post by:
How to retrive property values from our own property window
6
by: spmm_pls | last post by:
Hi, Could some1 please tell me what the best way is to adjust the value of a column in my databound datagrid (in ASP.NET) For example my database returns the values 1,2 and 3 in the column...
2
by: Dave | last post by:
Hello all, I need to know if you can vertically align Items within an ItemTemplate. For example I have two columns, one column has a stack of 6 textboxes, my second column can have 1 to n...
3
by: John E. | last post by:
I have a datatable that I am binding to a C# ASP.NET 1.1 web page datagrid. I also want to put an "Edit" column on the datagrid. However, whenever I use the following code, it puts the Edit...
4
by: Fred Nelson | last post by:
Hi: I have a VB.NET web app that contains a datagrid on a web form that is loaded as follows: DataGrid1.DataSource = lookup.searchnames(getinformation) DataGrid1.DataBind The grid displays...
1
by: Gomathi | last post by:
hi all, I have a datagrid in my application. If i bind some data source to that datagrid, its working fine for Internet explorer. If i'm using Netscape then its showing entire value( i.e the...
28
by: kiqyou_vf | last post by:
I'm trying to pull data from 2 different tables and do a loop to retrieve more than one row. I'm having problems with aligning the information. Can someone lead me in the right direction? I've done...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.