DataGrid Dynamic HeaderText

S

Seli

Hell

How can I change the headerText of an AutoGenerateColumns DataGrid

myDataGrid.DataSource=ds.Tables["Products"].DefaultView
myDataGrid.DataBind()
myDataGrid.Columns[0].HeaderText="MARCEL";

in the third line I get always an exception. myDataGrid.Colums.count Returns 0!

Thank
Seli
 
S

SB

Seli,
You can do that in the ItemCreated event.of the DataGrid.
Make sure that you only apply the value when the IteMType is of type header
=>

//I write from scratch, not Iin VS so there might be typo mistakes
if (e.Item.ItemType==ListItemType.HeaderItem){
e.Item[0].HeaderText="MARCEL";
}
Selim
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top