hi

I want to change the width of column in Gridview bound field but it is not changing .

Code Is

<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address">
                        <ItemStyle Width="500px" />
                        </asp:BoundField>

thanx

Dani AI

Generated

BoundField width settings often appear to be ignored because the browser decides column sizes based on the table’s layout algorithm and the actual cell content. ItemStyle/HeaderStyle on a BoundField sets styles on the <td>/<th>, but long unbroken text, CSS frameworks (Bootstrap), a parent width, or the default table-layout:auto can override those widths. ’s suggestion will fix many simple cases; when it “didn't work” (seen from ), the root cause is usually CSS specificity or the rendered HTML, not the ASP.NET attribute itself.

Practical fixes that reliably work:

  • Force a fixed table layout on the GridView and give the table a width so column widths are honored. Use a CSS class on the GridView and set table-layout: fixed; then set a column-specific rule that controls overflow and ellipsis. Example:

    <style>
    .myGrid { table-layout: fixed; width:100%; }
    .myGrid .colAddress { width:200px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
    </style>
    
    <asp:TemplateField HeaderText="Address">
      <ItemTemplate>
        <div class="colAddress"><%# Eval("Address") %></div>
      </ItemTemplate>
    </asp:TemplateField>
  • Use a TemplateField (shown above) when content needs wrapping or trimming — it gives full control over the inner markup and CSS.

  • As an alternative, set the width in code on row creation/data-bound: assign e.Row.Cells[index].Style["width"] = "200px"; from RowCreated/RowDataBound for deterministic output.

Troubleshooting checklist: inspect the rendered table with browser devtools and check computed styles; look for conflicting CSS selectors or Bootstrap table classes; check for long strings without spaces (add word-break or overflow rules); ensure AutoGenerateColumns is false if specific widths are required. ’s idea of adding columns server-side also helps when column definitions need to be exact at render time.

Recommended Answers

All 5 Replies

Have you tried?

<asp:GridView ID="dad" runat="server">
        <Columns>
            <asp:BoundField ItemStyle-Width="500px" />
        </Columns>
    </asp:GridView>

didn't work

What croker10 posted, works for me.
If you're still having problems with that, try adding the columns/rows data dinamically on server side

<asp:TextBox ID="instorid" width="40px" runat="server"></asp:TextBox>

Full Source : Tutorial

Mitch

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.