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">

    by
    sabarinathan.R
    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" />
    <Columns>
    <asp:TemplateField HeaderText="<input type="checkbox" align="center">">
    <ItemTemplate>
    <asp:CheckBox ID="chkdelete" runat="server"
    AutoPostBack="True" CausesValidation="True" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="id" HeaderText="ID" InsertVisible="False"
    ReadOnly="True" SortExpression="id" />
    <asp:TemplateField HeaderText="Category">
    <ItemTemplate>
    <asp:HyperLink ID="HlnkShow" runat="server" Text='<%#Eval("categoryname") %>' NavigateUrl='<%# "~/dropdown.aspx?categoryname=" + Eval("categoryname")%>'></asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="catpath" HeaderText="Parent Category"
    SortExpression="catpath" />
    <asp:ImageField HeaderText="Published" DataImageUrlField="Published"
    DataImageUrlFormatString="tick123.png">
    </asp:ImageField>
    </Columns>
    <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" />
    </asp:GridView>
























    [URL=http://www.deezer.name ]deezer[/URL], [URL=http://www.pandora-music.name/ ]pandora[/URL], [URL=http://www.limewire.name/ ]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
    HeaderStyle-Width="60px"

    Regards,
    SonyShiva
    Never lose hope..You never know what tomorrow will bring

  • #648147
    Hello,

    check this:


    You can fix the width as shown below.

    <Columns>

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



    Regards
    Rajesh

    Regards
    Mr.Rajesh
    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.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


  • 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.