You must Sign In to post a response.
  • Category: ASP.NET

    How can i adjust gridview column and width size

    how can i adjust column and width size as well as allow page settings also in gridview
  • #648088
    hi using this highlighted property u can set width to each column

    <asp:TemplateField HeaderText="SubClass Margin" HeaderStyle-Width="50px"ItemStyle-Width="50px">

    Be in first....
    but don't feel for being last

  • #648092
    try this
    <asp:TemplateField HeaderText="SubClass Margin" HeaderStyle-Width="30px"ItemStyle-Width="30px">

  • #648095
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
    DataSourceID="SqlDataSource1" Width="1300px" style="margin-left:5px"
    Height="800px" CellPadding="0" AllowPaging="True"
    GridLines="Vertical" ForeColor="#333333" AllowSorting="True" >

    <RowStyle BackColor="#E3EAEB" />
    <RowStyle BackColor="#EFF3FB" />
    <asp:TemplateField HeaderText="<input type="checkbox" align="center">">
    <asp:CheckBox ID="chkdelete" runat="server"
    AutoPostBack="True" CausesValidation="True" />
    <asp:BoundField DataField="id" HeaderText="ID" InsertVisible="False"
    ReadOnly="True" SortExpression="id" />
    <asp:TemplateField HeaderText="Category">
    <asp:HyperLink ID="HlnkShow" runat="server" Text='<%#Eval("categoryname") %>' NavigateUrl='<%# "~/dropdown.aspx?categoryname=" + Eval("categoryname")%>'></asp:HyperLink>
    <asp:BoundField DataField="catpath" HeaderText="Parent Category"
    SortExpression="catpath" />
    <asp:ImageField HeaderText="Published" DataImageUrlField="Published"
    <FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" />
    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#7C6F57" />
    <AlternatingRowStyle BackColor="White" />

    [URL= ]deezer[/URL], [URL= ]pandora[/URL], [URL= ]limewire[/URL]

  • #648096
    the above thatone is my gridview code where can i change for gridview columns and rows width.

  • #648116
    Hi chanti,

    You set the 'HeaderStyle-Width' property of your columns as you wish.
    If you dont want for checkkbox columns omit those.
    And apply for the remaining w.r.t. to your content, guess and adjust.
    Like this you do for columns

    Never lose hope..You never know what tomorrow will bring

  • #648147

    check this:

    You can fix the width as shown below.


    <asp:BoundField DataField="" HeaderText="" ItemStyle-Width="5%" ItemStyle-VerticalAlign="Top" />


    Software Engg.

  • #648410
    Hai Chanti,

    There are 2 ways to fix the column width in the gridview-

    1. Compile Time
    2. At Runtime

    At the compile time, we can set the column width by using the below snippet:

    <asp:TemplateField HeaderText="Employee Name" HeaderStyle-Width="80px" ItemStyle-Width="80px">

    At the run time, you can set the column width as :

    protected void gvPoolStatus_OnRowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.Header)
    e.Row.Cells[0].Text = string.Empty;
    e.Row.Cells[0].Width = Unit.Pixel(60);
    e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Left;

    Hope it will help.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.