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

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
 
E

Eliyahu Goldin

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
 
A

Adam Boczek

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.
 
E

Eliyahu Goldin

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

Eliyahu
 
A

Adam Boczek

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.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top