Dynamically accessing the top <td> attributes in a DataGrid

F

foldface

Hi
Taking the DataGrid as a table:
(1) I can access the <tr> attributes via

DataGrid1.HeaderStyle.Width = 301; // and similiar

(2) I can access the <td> attributes of the main body cells via

DataGridItem a = DataGrid1.Items[0];
a.Cells[0].Attributes.Add("width", "50");

or similiar

(3) I can access the body, i.e. between <td> and </td> of any cell
via ITemplate children

The problem is I want to access the top <td> attributes, i.e. those
in the header. Is there any way of doing that?

I also want to set the column widths dynamically of an empty DataGrid,
the above would enable me to accomplish that, is there any other way of
doing this.
NB web forms only. Have found lots of answers for windows forms

Ta
F
 
F

foldface

I also want to set the column widths dynamically of an empty DataGrid,

Nb. I also need to set the widths to be something like

50, 100, 0*

but I can't see anyway of setting a Unit to be "0*" as its a generic thing
and I think only tables support this

Ta
F
 
F

foldface

itemdatabound event is the way to go, something like this

private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
// get complete access to every td attribute and text content via this!
foreach(TableCell cell in e.Item.Cells)
{
cell.Attributes.Add("width", "99");
}
}
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top