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

<divclass="container"style="width: 500px"><asp:GridViewID="GridView1"runat="server"CssClass="gvData"AllowSorting="True"AutoGenerateColumns="False"DataSourceID="QuotationSQLDS"onrowdatabound="GridView1_RowDataBound"ForeColor="Black"><HeaderStyleHorizontalAlign="Center"Font-Size="8pt" /><Columns><asp:BoundFieldDataField="Id"HeaderText="Id"ReadOnly="True"SortExpression="Id"/><asp:BoundFieldDataField="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"