日期:2014-05-20  浏览次数:20492 次

GridView设置一个最小宽度,(不是固定值,根据页面打开时的宽度)
为了不让GridView字段的内容向下扩展破坏整个页面的高度.我把每列数据都设置了:
<ItemStyle   Wrap= "False "   />
<HeaderStyle   Wrap= "False "   />

但是,如果字段比较少时,尤其是GridView没有数据时,整个GridView变得非常窄,整个页面上,只有一点点宽度的GridView.非常难看.
有个想法:给GridView设置一个最小宽度,没有数据,或数据列数少时,整个GridView自动按比例扩展到整个区域中.如果超出,就出现左右拉的滚动条.
请问,如何实现?
<body   bgcolor= "#E4E4E4 "   leftmargin= "0 "   topmargin= "0 "   >
        <form   id= "form1 "   runat= "server ">
        <div>
        <table   width= "98% "   align= "center "   height= "100% "   border= "0 "   cellpadding= "0 "   cellspacing= "0 "   bgcolor= "E7E7E7 ">
        <tr>
        <td   valign= "top "   bgcolor= "E7E7E7 ">
                <!--   记录区域   开始   --->
        <div   id= "divGridView "   style= "position:absolute;left:10px;top:46px;width:100%;height:100%;z-index:1;overflow:   auto; ">
                    <table   border= "0 "   width= "100% "   height= "95% "   cellspacing= "0 "   cellpadding= "0 ">
                        <tr>  
                            <td   valign= "top ">
                                        <asp:GridView   ID= "GridView1 "   runat= "server "   EmptyDataText= "没有记录! "   AutoGenerateColumns= "False "   BackColor= "#F2F2F2 "   AllowSorting= "True "   OnSorting= "GridView1_Sorting "   AllowPaging= "True "   HorizontalAlign= "Left "   OnRowDataBound= "GridView1_RowDataBound ">
                                                <Columns>
                                                        <asp:BoundField   HeaderText= "编号 "   DataField= "Id "   Visible= "False "   />
                                                        <asp:TemplateField   HeaderText= "选择 ">
                                                                <ItemTemplate>
                                                                        <input   type= "radio "   id= "RadioName "   name= "RadioName "   value= ' <%#   Eval( "Id ")%> '   />