如何在ListView控件中修改此列的区域/大小?

时间:2013-02-03 05:49:16

标签: asp.net listview styles

我是一名新的ASP.NET开发人员,我面临着ListView风格的问题。风格运作良好,但现在我看不到右边的最后一列,我不知道为什么如此快照所示:

enter image description here

这是我的原始代码:

<asp:ListView ID="All_ListView" runat="server"  DataKeyNames="ID" DataSourceID="SqlDataSource1">
                        <LayoutTemplate>
                            <div ><table id="thetable" cellpadding="4px" cellspacing="1px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                                <thead>
                                    <tr style="background-color:#C6D7B5;">
                                        <%--<th style="border-right:2px solid white;border-bottom:2px solid #003366; ">LL No.</th>--%>
                                        <th style="border-bottom:2px solid #003366; ">
                                            <asp:CheckBox ID="CheckBox1" runat="server" CssClass="chkBoxPosition" OnCheckedChanged="CheckBoxHeader_All" AutoPostBack="true" />
                                        </th>    
                                        <th style="border-bottom:2px solid #003366; ">Title</th>
                                        <th style="border-bottom:2px solid #003366; ">Description</th>
                                        <th style="border-bottom:2px solid #003366; ">Type</th>
                                        <th style="border-bottom:2px solid #003366; ">Username</th>
                                        <th style="border-bottom:2px solid #003366; ">Name</th>
                                        <th style="border-bottom:2px solid #003366; ">Division</th>
                                        <th style="border-bottom:2px solid #003366; ">Submitted Date</th>
                                        <th style="border-bottom:2px solid #003366; ">Status</th>
                                    </tr>
                                </thead>
                                <tbody><tr id="itemPlaceholder" runat="server"></tr></tbody>
                            </table></div>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <asp:CheckBox ID="CheckBox2" runat="server" />
                                    </td>
                                <td>
                                    <asp:Label runat="server" ID="lblTitle" Text='<%#Eval("Title") %>'></asp:Label>
                                    </td>
                                <td>
                                    <asp:Label runat="server" ID="lblDescription" Text='<%#Eval("Description")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblType" Text='<%#Eval("Type")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblUsername" Text='<%#Eval("Username") %>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblName" Text='<%#Eval("Name") %>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblDivision" Text='<%#Eval("DivisionShortcut") %>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblSubmittedDate" Text='<%#Eval("DateSubmitted")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:LinkButton runat="server" ID="lnkSuggestionStatus" Text='<%#Eval("Status")%>'
                                                            OnClick="lnkSuggestionStatus_Click">
                                    </asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>                
                </asp:ListView>

我更改了第二列的宽度,该列占据了列表视图的大部分区域,看看我在更改时发生了什么

<asp:ListView ID="All_ListView" runat="server"  DataKeyNames="ID" DataSourceID="SqlDataSource1">
                        <LayoutTemplate>
                            <div ><table id="thetable" cellpadding="4px" cellspacing="1px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                                <thead>
                                    <tr style="background-color:#C6D7B5;">
                                        <%--<th style="border-right:2px solid white;border-bottom:2px solid #003366; ">LL No.</th>--%>
                                        <th style="border-bottom:2px solid #003366; ">
                                            <asp:CheckBox ID="CheckBox1" runat="server" CssClass="chkBoxPosition" OnCheckedChanged="CheckBoxHeader_All" AutoPostBack="true" />
                                        </th>    
                                        <th style="border-bottom:2px solid #003366; ">Title</th>
                                        <th style="border-bottom:2px solid #003366; ">Description</th>
                                        <th style="border-bottom:2px solid #003366; ">Type</th>
                                        <th style="border-bottom:2px solid #003366; ">Username</th>
                                        <th style="border-bottom:2px solid #003366; ">Name</th>
                                        <th style="border-bottom:2px solid #003366; ">Division</th>
                                        <th style="border-bottom:2px solid #003366; ">Submitted Date</th>
                                        <th style="border-bottom:2px solid #003366; ">Status</th>
                                    </tr>
                                </thead>
                                <tbody><tr id="itemPlaceholder" runat="server"></tr></tbody>
                            </table></div>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <asp:CheckBox ID="CheckBox2" runat="server" />
                                    </td>
                                <td>
                                    <asp:Label runat="server" ID="lblTitle" Text='<%#Eval("Title") %>'></asp:Label>
                                    </td>
                                <td>
                                    <asp:Label runat="server" ID="lblDescription" Text='<%#Eval("Description")%>' Width="50%"></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblType" Text='<%#Eval("Type")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblUsername" Text='<%#Eval("Username") %>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblName" Text='<%#Eval("Name") %>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblDivision" Text='<%#Eval("DivisionShortcut") %>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblSubmittedDate" Text='<%#Eval("DateSubmitted")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:LinkButton runat="server" ID="lnkSuggestionStatus" Text='<%#Eval("Status")%>'
                                                            OnClick="lnkSuggestionStatus_Click">
                                    </asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>                
                </asp:ListView>

你可以帮我解决这个显示问题吗?

2 个答案:

答案 0 :(得分:1)

嗨,你可以试试这个。

int height = listView1.Items[0].Bounds.Height + listView1.Items[listView1.Items.Count - 1].Bounds.Bottom;

listView1.Size = new Size(400, height);

答案 1 :(得分:1)

我怀疑你的列表视图位于div,面板或其他一些具有固定宽度的父控件内,例如600px,因为你改变了第二列的宽度,其他列没有足够的空间显示,我猜不会在div上设置溢出。

您有两种选择:

  1. 从此父控件中删除ListView,以便它可以根据需要动态调整大小
  2. 如果内容溢出超出固定宽度,则为div创建一个CSS样式规则以显示滚动条:
  3. <强> CSS:

    #listViewParent
     {
       width:600px;
       float:left;
       overflow:auto;
     }
    

    <强> ASPX:

    <div id="listViewParent">
      Your ListView goes here
    </div>