Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:00:58+00:00 2026-05-27T03:00:58+00:00

I have a GridView which uses BoundField for columns. I am trying to set

  • 0

I have a GridView which uses BoundField for columns. I am trying to set a maxwidth for my UserInfo column.

I have tried many many ways but non of them work. Below is the code for my GridView :

<asp:GridView ID="GridView1" AutoGenerateEditButton="True" 
ondatabound="gv_DataBound" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False">

<Columns>
                <asp:BoundField HeaderText="UserId" 
                DataField="UserId" 
                SortExpression="UserId"></asp:BoundField>

                <asp:BoundField HeaderText="Username" 
                DataField="Username" 
                SortExpression="Username"></asp:BoundField>

                <asp:BoundField HeaderText="UserInfo" 
                DataField="UserInfo" 
                SortExpression="UserInfo"></asp:BoundField>

                </Columns>
</asp:GridView>

Looking for suggestions on how I can set the width of a specific column, which is my UserInfo column.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:00:59+00:00Added an answer on May 27, 2026 at 3:00 am

    I did a small demo for you. Demonstrating how to display long text.

    In this example there is a column Name which may contain very long text. The boundField will display all content in a table cell and therefore the cell will expand as needed (because of the content)

    The TemplateField will also be rendered as a cell BUT it contains a div which limits the width of any contet to eg 40px. So this column will have some kind of max-width!

        <asp:GridView ID="gvPersons" runat="server" AutoGenerateColumns="False" Width="100px">
            <Columns>
                <asp:BoundField HeaderText="ID" DataField="ID" />
                <asp:BoundField HeaderText="Name (long)" DataField="Name">
                    <ItemStyle Width="40px"></ItemStyle>
                </asp:BoundField>
                <asp:TemplateField HeaderText="Name (short)">
                    <ItemTemplate>
                        <div style="width: 40px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis">
                            <%# Eval("Name") %>
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    

    enter image description here

    Here is my demo codeBehind

     public partial class gridViewLongText : System.Web.UI.Page
     {
         protected void Page_Load(object sender, EventArgs e)
         {
             #region init and bind data
             List<Person> list = new List<Person>();
             list.Add(new Person(1, "Sam"));
             list.Add(new Person(2, "Max"));
             list.Add(new Person(3, "Dave"));
             list.Add(new Person(4, "TabularasaVeryLongName"));
             gvPersons.DataSource = list;
             gvPersons.DataBind();
             #endregion
         }
     }
    
     public class Person
     {
         public int ID { get; set; }
         public string Name { get; set; }
    
         public Person(int _ID, string _Name)
         {
             ID = _ID;
             Name = _Name;
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET GridView that uses template columns and user controls to allow
I have a gridview which contains columns vacancy id and vacancy title and a
I have a gridview which displays rows and columns all linked to an sql
I have a gridview which uses a stored procedure with session[UserName] as a parameter
I have a webform which uses a gridview control to show result of a
I have gridview which has columns of data and a button below the Apply
I have one GridView which has multiple columns. Here I just mentioned only the
I have a GridView that is bound to a DataTable, which in turn uses
I have GridView which I can select a row. I then have a button
I have a gridview which is databound, I want to dynamically add a row

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.