首页 > 解决方案 > 更改 ListView 中列的宽度(c#)

问题描述

我是 ListView 的新手,我试图改变列的宽度(表格很大)。似乎更改表格中的样式标签不起作用。我可以做些什么来减小表格大小以完全适合屏幕?

 <LayoutTemplate>
                <table runat="server" id="table1" cellpadding="2" style="width:500px">
                        <tr id="tr1" runat="server" style="Background:yellow" >
                            <th id="th1" runat="server" style="Color:Blue"><asp:LinkButton id="link1" OnClick="link1_Click"
                            runat="server" style="Color:Blue">a</asp:LinkButton></th>
                            <th id="th2" runat="server" style="Color:Blue">b</th>
                            <th id="th3" runat="server" style="Color:Blue">c</th>
                            <th id="th4" runat="server" style="Color:Blue"> <asp:LinkButton id="link2" OnClick="link2_Click"
                             runat="server" style="Color:Blue"> d</asp:LinkButton> </th>
                             <th id="th5" runat="server" style="Color:Blue">e</th>
                              <th id="th6" runat="server" style="Color:Blue"> <asp:LinkButton id="link3" OnClick="link3_Click"
                             runat="server" style="Color:Blue">f</asp:LinkButton> </th>
                            <th id="th7" runat="server" style="Color:Blue">Edit</th>
                            <th id="th8" runat="server" style="Color:Blue">Delete</th>
                      </tr>
                      <tr runat="server" id="itemPlaceholder" />
                </table>
                         </LayoutTemplate> 
                   <ItemTemplate>
                  <tr id="tr2" runat="server" style="background:#D9D8E0">
                 <td> <asp:Label ID="Label1" runat="Server" Text='<%#Eval("flda") %>' /></td>
                 <td> <asp:Label ID="Label2" runat="Server" Text='<%#Eval("fldb") %>' /></td>
                 <td> <asp:Label ID="Label3" runat="Server" Text='<%#Eval("fldc") %>' /></td>
                 <td> <asp:Label ID="Label4" runat="Server" Text='<%#Eval("fldd") %>' /></td>
                 <td> <asp:Label ID="Label5" runat="Server" Text='<%#Eval("flde") %>' /></td>
                 <td> <asp:Label ID="Label6" runat="Server" Text='<%#Eval("fldf") %>' /></td>
                 <td> <asp:Button ID="button1" runat="Server" Text="Edit" CommandName="edit" /> </td>  
                <td> <asp:Button ID="button2" runat="Server" Text="Delete" CommandName="Delete" /></td>
                 </tr>
                    </ItemTemplate> 

标签: c#listviewstyles

解决方案


而不是在样式属性中传递宽度。

 <table runat="server" id="table1" cellpadding="2" style="width:500px">

尝试添加宽度属性,如下所示。

<table cellpadding="2" width="500px" border="1" runat="server" id="table1">

推荐阅读