开发者

Unable to set GridView row widths on RowDataBound

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜