Skip to content Skip to sidebar Skip to footer

How To Make A GridView With Maxmimum Size Set To The Containing DIV

I want to fix the size of a GridView depending on the DIV containing it. I changed every possible attribute but nothing changes in the gridview. Here is the markup:

Solution 1:

Try doing something like this

add class to both gridview and containing div

<div class="container" style="width: 500px">
         <asp:GridView ID="GridView1" runat="server" CssClass="gvData"
                       AllowSorting="True" AutoGenerateColumns="False" 
                       DataSourceID="QuotationSQLDS" 
                       onrowdatabound="GridView1_RowDataBound"  
                       ForeColor="Black">
                <HeaderStyle HorizontalAlign="Center" Font-Size="8pt" />
                <Columns>
                     <asp:BoundField DataField="Id" HeaderText="Id" 
                                     ReadOnly="True" SortExpression="Id"/>
                     <asp:BoundField DataField="description" 
                                     HeaderText="Description" 
                                     SortExpression="description" />
                </Columns>
          </asp:GridView>
    </div>

And use jQuery and do something like this:

$(document).ready(function () {
   var height = $('.container').height();
   $('.gvData').height(height);
});

and in your .css:

.container{height:auto; float:left;overflow:hidden;display:block;}

Solution 2:

I think it should work if you are looking your grid view to be as broad as 500px. Is it getting broader than that?


Post a Comment for "How To Make A GridView With Maxmimum Size Set To The Containing DIV"