Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Click here for a picture of the issue i am getting with the paging number being too far
[^]


ASP.NET
<pre><asp:GridView ID="GridView1" runat="server" CssClass="fixedColWidth" CellPadding="0" ForeColor="#333333" Height="273px" AutoGenerateEditButton="True"  OnRowEditing="GridView1_RowEditing"         
        OnRowCancelingEdit="GridView1_RowCancelingEdit" 
        OnRowUpdating="GridView1_RowUpdating"
        OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True" PageSize="1000">
              <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <%--<Columns>
                    <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
                </Columns>--%>
              <EditRowStyle BackColor="#999999" />
              <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
              <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
              <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Left"/>
              <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
              <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
              <SortedAscendingCellStyle BackColor="#E9E7E2" /> 
              <SortedAscendingHeaderStyle BackColor="#506C8C" />
              <SortedDescendingCellStyle BackColor="#FFFDF8" />
              <SortedDescendingHeaderStyle BackColor="#6F8DAE" />


My Css class for the gridview is below which is used to give the columns a max and min width of 150px because i have dropdowns correlated which are the same px size.

<style>
     .fixedColWidth td
     {
     min-width : 150px;
     max-width : 150px;
            }
</style>


What I have tried:

i tried to do this from stack overflow but then it removes the column size of 150 px.
asp.net - page numbers are too far in GridView - Stack Overflow[^]
Posted
Updated 7-Mar-17 4:20am

1 solution

Look at the generated HTML. You'll see that the pager is rendered as a child table within a row at the bottom of the main GridView table:
HTML
<table class="fixedColWidth" ...>
    ...
    <tr>
        <td colspan="...">
            <table>
                <tr>
                    <td>
                        1
                    </td>
                    <td>
                        <a ...>2</a>
                    </td>
                    ...
                </tr>
            </table>
        </td>
    </tr>
</table>

Your CSS rule says that any <td> within the main table should have a fixed width of 150px. This includes the <td>s nested within the pager table.

You'll need to change your rule so that it only applies to the immediate children of the GridView. (Depending on your settings, you might need to account for a <thead> / <tbody> as well.)
CSS
.fixedColWidth > tr > td,
.fixedColWidth > tbody > tr > td,
.fixedColWidth > thead > tr > td,
.fixedColWidth > tfoot > tr > td
{
    min-width: 150px;
    max-width: 150px;
}
 
Share this answer
 
Comments
JT1992 7-Mar-17 10:24am    
oh thank you. i understand why this was happening. i thought just making the td 150 would make everything be that way. Thank you sir!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900