【问题标题】:How to Stretch Gridview width inside a Div or a Panel in ASP.Net如何在 ASP.Net 中的 Div 或面板内拉伸 Gridview 宽度
【发布时间】:2016-06-02 08:01:45
【问题描述】:

根据上图。我有一个我喜欢被拉伸的gridview,它包含了它在里面镶板的整个div。问题是当它根据内容宽度自动调整时。

gridview 与使标题固定的 javascript 命令合并。我实际上可以通过在 gridview 中放置 width=100% 属性来获得所需的输出。但是,由于它注入了 jquery 命令,所以当我包含宽度属性时,它会导致此

这里是代码

     <div class="GridviewPanelBody">


      <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" Font-Size="Smaller" EmptyDataText="No Records Found" ShowHeaderWhenEmpty="True"  AutoGenerateColumns="false" >
<emptydatarowstyle backcolor="white" forecolor="black"/>             
<AlternatingRowStyle BackColor="White" />

    <Columns>
        <asp:BoundField HeaderText="Location" DataField="locationd" />
        <asp:BoundField HeaderText="Retail Partner" DataField="name"   />
        <asp:BoundField HeaderText="FL Area" DataField="sqm"   />
        <asp:BoundField HeaderText="Previous Month" DataField="PreviousMonth" DataFormatString="{0:#,##0.00;(#,##0.00);0}"  />
         <asp:BoundField HeaderText="Current Month" DataField="CurrentMonth" DataFormatString="{0:#,##0.00;(#,##0.00);0}" />
         <asp:BoundField HeaderText="Last Year Month" DataField="LastYearMonth" DataFormatString="{0:#,##0.00;(#,##0.00);0}" />
          <asp:BoundField HeaderText="Sales/SQM" DataField="SALES/SQM"  DataFormatString="{0:#,##0.00;(#,##0.00);0}"/>
          <asp:BoundField HeaderText="Inc/Dec%" DataField="INC/DEC%"  DataFormatString="{0:#,##0.00;}" />

         </Columns>

       <FooterStyle BackColor="#CCCC99" />
       <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" Height="25px"/>
       <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
     <RowStyle BackColor="#F7F7DE" />
     <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
      <SortedAscendingCellStyle BackColor="#FBFBF2" />
      <SortedAscendingHeaderStyle BackColor="#848384" />
      <SortedDescendingCellStyle BackColor="#EAEAD3" />
      <SortedDescendingHeaderStyle BackColor="#575357" />
  </asp:GridView>

</div>

css的一部分

 .GridviewPanelBody
{
             background-color: #FaFaFa;

             margin-left: auto;

             margin-right: auto;

             overflow: auto;

             height: auto;   

}

【问题讨论】:

    标签: javascript c# jquery css asp.net


    【解决方案1】:

    为您的 gridview 对象添加宽度属性:

    <asp:GridView ID="gvPersons" runat="server" AutoGenerateColumns="False" Width="100px">
    

    并且,将列的 AutoSizeMode 属性设置为 AllCells。

    【讨论】:

    • 我实际上放置了一个 width="100%" 属性,但结果它为 gridview 获得了一列输出(请参阅问题中的第二张图片)我相信这是因为jquery 插件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    相关资源
    最近更新 更多