Rohit Prakash
Rohit Prakash

Reputation: 1972

How to set integer datatype column data alignment to left?

I have a datatable in which one of the column is of integer type. Now after binding it to a GridView, integer column data are being aligned to right side of the column, But I want it to be left side as exactly the string type column.

How can I achieve it?

Upvotes: 0

Views: 897

Answers (4)

Suraj Singh
Suraj Singh

Reputation: 4059

  <asp:BoundField HeaderText="xxxxx" ItemStyle-HorizontalAlign="Left" DataField="xxxxx"
                    SortExpression="xxxxxx" />

-------------------------------------------OR

At rowbound event check for integer value and left align that column .

Upvotes: 0

Microsoft DN
Microsoft DN

Reputation: 10020

dataGridView1.Columns["CustomerName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; 

Upvotes: 2

Vy Le
Vy Le

Reputation: 68

You can use ItemStyle to align your column

<asp:BoundField DataField="yourColumn">
    <ItemStyle HorizontalAlign="Left" />
</asp:BoundField>

Upvotes: 0

Steve
Steve

Reputation: 216293

In a DataGridView you could align a column with

 this.dataGridView1.Columns["ColumnName"].DefaultCellStyle.Alignment = 
                  DataGridViewContentAlignment.MiddleLeft; 

Other values for the enumeration DataGridViewContentAlignment

By the way, if you want to align also the header caption you could use the same enumeration for the HeaderCell

 this.dataGridView1.Columns["ColumnName"].HeaderCell.Style.Alignment = 
         DataGridViewContentAlignment.MiddleLeft;

Upvotes: 2

Related Questions