开发者

How to suppress adjusting a column width in a gridview

I know my question has been asked before b开发者_运维问答ut I still have no answer.

I have a gridview with AutoGenerateColumns="False". The width of every column is set explicitly with the HeaderStyle-Width and ItemStyle-Width properties.

What happens is that if the data coming to a BoundField column contains some multi-word text, the width of the column gets adjusted by the maximum width of the words. For example, if there are two rows in the dataset: "Hello World" and "I like programming", the grid will be adjusted by the word "programming".

I've tried to play with the Wrap properties but it doesn't help.

Can you please help? Thanks LG


Try setting the HeaderStyle-CssClass and ItemStyle-CssClass to a CSS class which you can use to set the required width:

<asp:BoundField HeaderStyle-CssClass="restricted-width-column" ItemStyle-CssClass="restricted-width-column" ...

...

<style type="text/css">
    .restricted-width-column
    {
        width:50px;
        overflow:hidden;
        display:block;
        white-space:nowrap;
    }
</style>

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜