我该如何重新定位ListView

时间:2011-07-17 06:58:18

标签: asp.net css visual-studio-2010

我在设计视图中有一个ListView,但是我无法用绝对的css属性移动它。

有没有办法在页面上移动它?

     <asp:ListView ID="ListView1" runat="server" DataKeyNames="MessageID" 
        DataSourceID="SqlDataSource1" onitemcommand="ListView1_ItemCommand" 
        style="z-index: 1; left: 452px; top: 429px; position: absolute; height: 271px; width: 221px; margin-top: 0px">
        <LayoutTemplate>
                <table runat="server">
                  <tr runat="server">
                      <td runat="server">
                          <table ID="itemPlaceholderContainer" runat="server" border="1" 
                              style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                              <tr runat="server" style="background-color: #FFFBD6;color: #333333;">
                                  <th runat="server">
                                      MessageTitle</th>

                              </tr>
                              <tr ID="itemPlaceholder" runat="server">
                              </tr>
                          </table>
                      </td>
                  </tr>
                    <tr runat="server">
                        <td runat="server" 
                            style="text-align: center;background-color: #FFCC66;font-family: Verdana, Arial, Helvetica, sans-serif;color: #333333;">
                            <asp:DataPager ID="DataPager1" runat="server">
                                <Fields>
                                    <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                        ShowLastPageButton="True" />
                                </Fields>
                            </asp:DataPager>
                        </td>
                    </tr>
                </table>
        </LayoutTemplate>

        <AlternatingItemTemplate>
            <tr style="background-color: #FAFAD2;color: #284775;">
                <td>
                    <asp:LinkButton ID="LinkButton1" runat="server"  CommandName="Select">'<%# Eval("MessageTitle") %>'</asp:LinkButton>


                </td>

            </tr>
        </AlternatingItemTemplate>
        <EditItemTemplate>
            <tr style="background-color: #FFCC66;color: #000080;">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Cancel" />
                </td>
                <td>
                    <asp:TextBox ID="MessageTitleTextBox" runat="server" 
                        Text='<%# Bind("MessageTitle") %>' />
                </td>

            </tr>
        </EditItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" 
                style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                <tr>

                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" />
                </td>
                <td>
                    <asp:TextBox ID="MessageTitleTextBox" runat="server" 
                        Text='<%# Bind("MessageTitle") %>' />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </InsertItemTemplate>

        <ItemTemplate>
            <tr style="background-color: #FFFBD6;color: #333333;">
                <td>
               <asp:LinkButton ID="LinkButton1" runat="server"  CommandName="Select" >'<%# Eval("MessageTitle") %>'</asp:LinkButton>
                </td>    
            </tr>
        </ItemTemplate>
        <SelectedItemTemplate>
            <tr style="background-color: #FFCC66;font-weight: bold;color: #000080;">
                <td>
                  <asp:LinkButton ID="LinkButton1" runat="server"  CommandName="Select">'<%# Eval("MessageTitle") %>'</asp:LinkButton>
                </td>

            </tr>
        </SelectedItemTemplate>
    </asp:ListView>




    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CP_AllQuestionsAnswered %>" 
        SelectCommand="GetMessagesTitles" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter Name="Name" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

1 个答案:

答案 0 :(得分:2)

出了什么问题:

div.ListView1
{
    position: absolute;
    left: 100;
    top: 100;
}

<asp:ListView runat="server" ID="ListView1" ItemPlaceholderID="itemPlaceholder">
    <LayoutTemplate>
        <div class="ListView1">
            <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
        </div>
    </LayoutTemplate>
    <ItemTemplate>
        <%# Container.DataItem.ToString() %>
        <br />
    </ItemTemplate>
</asp:ListView>

好的,您的问题是您需要在布局模板中为表格指定此属性时设置ListView样式属性。