width of grid view boundfield
Asked Answered
S

6

23

I can not set the width of bound field. Is there any problem in the following markup.

 <asp:BoundField DataField="UserName" HeaderText="User Name"
                   meta:resourcekey="BoundFieldUNCUserNameResource1">
        <HeaderStyle Width="50%" />
 </asp:BoundField>

enter image description here

Please refer to the image. I set width using the following. The yellow colored numbers are corresponding width. The marked user name is always Wrapped even I set a width to a large value (say 50%) and set Wrap="false".

<HeaderStyle Width="20%" Wrap="true" />
<ItemStyle Width="20%" Wrap="true" />
Stelly answered 21/6, 2011 at 5:39 Comment(0)
S
37

Try This:

ItemStyle-Width="50%" ItemStyle-Wrap="false" in the BoundField tag

Shirtwaist answered 21/6, 2011 at 5:50 Comment(2)
ItemStyle-Width="120px" is not effective when Wrap="false". Why?Sheetfed
This seems to have no effect on asp:GridView.Luanneluanni
R
9

For BoundField:

 <asp:BoundField DataField="UserName" HeaderText="User Name" ItemStyle-Width="50px" />
Reticulum answered 21/6, 2011 at 6:19 Comment(0)
S
2

It's amazing that even now, in 2016, the ItemStyle-Width and HeaderStyle-Width attributes usually get ignored in the ASP.Net GridView control.

Sometimes, they just seem to create no markup whatsoever.

My solution was to give up trying to set this attributes, and I resorted to using plain old CSS instead:

.AspNet-GridView table tbody tr td:nth-child(1)
{
    /*  Set the width of the 1st GridView column */
    width: 200px;
}
.AspNet-GridView table tbody tr td:nth-child(2)
{
    /*  Set the width of the 2nd GridView column */
    width: 300px;
}
Stokowski answered 25/10, 2016 at 8:4 Comment(0)
L
0

I am also facing this problem today. What i got is you must define ur width in css class & called that css class in boundfeild. e.g.

HeaderStyle-CssClass="width350"
Lowenstern answered 30/1, 2018 at 6:47 Comment(0)
D
0

To change column width gridview boundfield just add this inside boundfield

ItemStyle-Width="200"  ItemStyle-Wrap="False"

it worked for me, try this

Disburse answered 4/9, 2018 at 6:53 Comment(0)
E
0

After trying several solutions with no luck, I was able to add a css class to the item. Seems like both HeaderStyle-CssClass and ItemStyle-CssClass attributes needed to be set:

    <asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-CssClass="Name" ItemStyle-CssClass="Name" />
Eulogistic answered 29/6, 2020 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.