Setting column header text of datagrid in PreRender... Do You know how to do it?

  • Thread starter Thread starter Adam Boczek
  • Start date Start date
A

Adam Boczek

I've a dropdownlist control to change language on my page. Because of page
lifetime, I have to set all my labels, texts etc. from ResourceManager in
prerender handler to be sure that culture change has been done. But I can't
set HeaderText property of DataGridColumn in prerender because it is
evaluated during data binding. I don't want to call DataBind() in
OnPreRender also... Any ideas?

I've tried to walk through Controls collection in PreRender, but it's very
poor, hard coded solution (and very problematic when we have some sortable
and not sortable columns)...

TIA
Adam
MCAD
 
Adam,

If you are talking about autogenerated columns, the proper place for
changing their names is ItemCreated event.

For manually added columns you can use either ItemDataBound or PreRender
event. Note, that data binding takes place before PreRender.

Eliyahu
 
Hi Eliyahu,

I don't use autogenereted columns ;))

Maybe I should say it more cleary. When you call DataBind on DataGrid,
it builds etire control from information stored in template objects.
Usually you call DataBind in OnLoad handler or in same postback event
handlers. That means that your grid (or martix of controls) is already
created in PreRender. I can't set DataGrid1.HeaderText = "MyHeader" in
PreRender because this is a template property and such change dosn't
affect.

I'd like to change my datagrid's headers according to launguage in
dropdownlist (autopostback). I can do it only in prerender handler (I
have a base class for all my datagrids). I can find header cells walking
through Controls (DataGrid.Controls[0].Controls[0] etc.) but I can't set
any Id to easy recognize "my" headers.
 
If DataGrid1.HeaderText = "MyHeader" doesn't effect in PreRender, what
about ItemDataBound event?

Eliyahu
 
ItemDataBound is triggered during data binding so you can't tell "when" it
fires. I'd like to change language on page using dropdownlist control (with
languages "supported" by page). That change will be first present in
dropdownlist change eventhandler and than I can set CurrentUICulture to
choosen language. All easy controls (ButtonLink etc.) are not "ready" until
prerender, so I can change any proprety like "text" of such control in
prerender without problems. Template controls are "ready" in prerender and
that's my problem :(

Adam

Eliyahu Goldin said:
If DataGrid1.HeaderText = "MyHeader" doesn't effect in PreRender, what
about ItemDataBound event?

Eliyahu

Adam Boczek said:
Hi Eliyahu,

I don't use autogenereted columns ;))

Maybe I should say it more cleary. When you call DataBind on DataGrid,
it builds etire control from information stored in template objects.
Usually you call DataBind in OnLoad handler or in same postback event
handlers. That means that your grid (or martix of controls) is already
created in PreRender. I can't set DataGrid1.HeaderText = "MyHeader" in
PreRender because this is a template property and such change dosn't
affect.

I'd like to change my datagrid's headers according to launguage in
dropdownlist (autopostback). I can do it only in prerender handler (I
have a base class for all my datagrids). I can find header cells walking
through Controls (DataGrid.Controls[0].Controls[0] etc.) but I can't set
any Id to easy recognize "my" headers.
 
Back
Top