Dynamically changing styles in DataGrid

T

tshad

I am trying to build a datagrid that is customizable by my clients.

I can hide and show columns or changes sizes of the Columns or DataGrid
itslef from the Page_PreRender event that works pretter well.

DataGrid1.Width = new Unit("551px")
for each col as DataGridColumn in DataGrid1.Columns
if col.HeaderText = "Company" orElse col.HeaderText = "Posted" then
col.Visible = false
end if
next

The sizing of the DataGrid (shown above) only works if the size is set by
"Width", ie:

<anthem:DataGrid
Visible=true
AllowSorting="false"
AutoGenerateColumns="false"
CellPadding="0"
CellSpacing="0"
ID="DataGrid2"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="0"
BorderColor="#999999"
Width="701px"
style="padding-right:5px">

If, however, I tried to use a style - the style seems to get applied AFTER
the PreRender event, ie:

<anthem:DataGrid
Visible=true
AllowSorting="false"
AutoGenerateColumns="false"
CellPadding="0"
CellSpacing="0"
ID="DataGrid2"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="0"
BorderColor="#999999"
style="padding-right:5px;width=701px">

In this example, the size of the table would be 701px instead of the 551px I
changed it to in the PreRender. The first example works fine:

How can I do this in the PreRender section (or another area) if the size is
set in a style?

Thanks,

Tom
 
T

tshad

marss said:
How can I do this in the PreRender section (or another area) if the size
is
set in a style?

If width is set by means of style then change style.
DataGrid1.Style["width"] = "551px";

So that's how that is done. I didn't know you could access the styles that
way.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top