Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   align data column from codebehind (http://www.velocityreviews.com/forums/t760681-align-data-column-from-codebehind.html)

news.microsoft.com 06-03-2004 03:58 PM

align data column from codebehind
 
Hello.
I've started a datagrid in codebehind and need to have the numeric columns
right aligned.

here's the code:
-----
Select Case arThis1(1)

Case "String"

dt.Columns.Add(New DataColumn(v, GetType(String)))

Case "Numeric"

dt.Columns.Add(New DataColumn(v, GetType(Integer)))

Case "Date"

dt.Columns.Add(New DataColumn(v, GetType(Date)))

End Select

-----
when the case is numeric, i would like to have that column
itemstyle-horizontalalign set to right. Is there a way to do this from
codebehind.

I've found a way to do this from the itemdatabound event, but I can't help
but thinking that this is the wrong way as it would be neccessary to set
global values, etc just to remember which columns, etc need this property.

Thanks for any assistance you can give.

Melissa



Raterus 06-03-2004 04:50 PM

Re: align data column from codebehind
 
Not quite sure what you are after, you are adding columns to a datatables, but you want to right-align this data in a DataGrid. I take it you, fill this datatable with whatever you need, then assign this whole datatable to the datasource of the datagrid? Perhaps then your AutoGenerateColumns=True of the datagrid, so you get some pretty non-customized output, which you want to customize just a tad and right align the numbers.

If that is the case, I would say do it in itemdatabound, keep track of the current index of the columns you added when adding to the datatable, then in itemdatabound, retrieve these, and set the tablecell so it right-aligns.

Hope this is even close to helpful :-)
--Michael

"news.microsoft.com" <Melissa@IHATEMicrosoft.com> wrote in message news:OffmYOYSEHA.3596@tk2msftngp13.phx.gbl...
> Hello.
> I've started a datagrid in codebehind and need to have the numeric columns
> right aligned.
>
> here's the code:
> -----
> Select Case arThis1(1)
>
> Case "String"
>
> dt.Columns.Add(New DataColumn(v, GetType(String)))
>
> Case "Numeric"
>
> dt.Columns.Add(New DataColumn(v, GetType(Integer)))
>
> Case "Date"
>
> dt.Columns.Add(New DataColumn(v, GetType(Date)))
>
> End Select
>
> -----
> when the case is numeric, i would like to have that column
> itemstyle-horizontalalign set to right. Is there a way to do this from
> codebehind.
>
> I've found a way to do this from the itemdatabound event, but I can't help
> but thinking that this is the wrong way as it would be neccessary to set
> global values, etc just to remember which columns, etc need this property.
>
> Thanks for any assistance you can give.
>
> Melissa
>
>


Amar 06-04-2004 06:45 AM

Re: align data column from codebehind
 
When you add the Columns of the Grid one by one , you must have
AutoGenerateColumns = false, for every BoundColumn you add you can add
any attribute you want....eg

BoundColumn bCol = new BoundColumn();
bCol.DataField = dt.Columns["name"].ColumnName; <-- Your DataTable
(dt)
..
..
..
and at the end before you add it to the GridColumnCollection
bCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
Columns.Add(bCol);

That's it!


"news.microsoft.com" <Melissa@IHATEMicrosoft.com> wrote in message news:<OffmYOYSEHA.3596@tk2msftngp13.phx.gbl>...
> Hello.
> I've started a datagrid in codebehind and need to have the numeric columns
> right aligned.
>
> here's the code:
> -----
> Select Case arThis1(1)
>
> Case "String"
>
> dt.Columns.Add(New DataColumn(v, GetType(String)))
>
> Case "Numeric"
>
> dt.Columns.Add(New DataColumn(v, GetType(Integer)))
>
> Case "Date"
>
> dt.Columns.Add(New DataColumn(v, GetType(Date)))
>
> End Select
>
> -----
> when the case is numeric, i would like to have that column
> itemstyle-horizontalalign set to right. Is there a way to do this from
> codebehind.
>
> I've found a way to do this from the itemdatabound event, but I can't help
> but thinking that this is the wrong way as it would be neccessary to set
> global values, etc just to remember which columns, etc need this property.
>
> Thanks for any assistance you can give.
>
> Melissa



All times are GMT. The time now is 05:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.