My current code to attempt to set widths for the rows on a gridview is:
protected void RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (DataControlFieldHeaderCell dcfhc in e.Row.Cells)
{
dcfhc.Width = 100;
}
}
else
{
foreach (DataControlFieldCell dcfc in e.Row.Cells)
{
dcfc.Width = 100;
}
}
}
But that just keep all of the widths default! What am I开发者_StackOverflow doing wrong?
EDIT: I have already tried thise code as well!
PoolToDBHeaders.DataSource = new DataView(headerTable);
PoolToDBHeaders.DataBind();
foreach (DataControlField dcf in PoolToDBHeaders.Columns)
{
dcf.ItemStyle.Width = 100;
}
PoolToDBHeaders.DataBind();
...why are you setting the widths in a databinding event? Just set them (using the Columns
property of the DataGrid) before databinding in the first place.
Setting them in a databinding event is silly anyways, since you can't possibly have different widths for different rows.
精彩评论