Dynamically changing styles in DataGrid

Tech-Archive recommends: Speed Up your PC by fixing your registry



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


.



Relevant Pages

  • Re: Add blank item to dropdown list in datagrid
    ... If you want to add the item into the ddl inside the grid, ... PreRender event. ... > I've got a dropdown list in the footer template of a datagrid. ... > Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: items.insert into dropdown in datagrid
    ... tried the origional code in the datagrid prerender, ... Dim ddlPsize As DropDownList ... insert ddl items for every datagrid item in the datagrid's ItemDataBound ... displays there are several rows of dropdowns but only the top dropdown ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: access all items in a datagrid
    ... You can loop through myGrid.Items collection. ... You are probably mostly interested in data row ... PreRender event. ... > I have a newbie datagrid question. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Button causing post
    ... on a page and a composite control made up of a calandar control and a text ... When the user selects a new date I need the datagrid to update based ... redrawn in the prerender method which is unnecessary for my purposes. ... >> page prerender and I don't want the code to execute if a certain button ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Detect which ImageButton caused PostBack
    ... If I bind in the prerender event, the datagrid doesn't change. ... >> I don't get the ItemCommand event because my DataGrid is being bound to ...
    (microsoft.public.dotnet.framework.aspnet)