表格显示问题

时间:2010-11-25 04:24:07

标签: c# asp.net html css

我有一个带有2个嵌套表的表,显示了我的两个中继器。我的中继器分别显示家庭和办公室地址。问题是每当我在一个转发器中添加新记录时,另一个转发器表的显示就会搞砸。就像我在rpt1中添加记录一样,然后rpt1的表向上移动,rpt2的表向下移动......标题不会显示在一行中。添加或删除记录时,它们会上下移动。我想要的是这些标题是固定的,所以如果我添加新记录或删除记录,两个转发器的标题显示在同一行...我该如何解决这个问题?希望它不会混淆。

<table width="100%" cellpadding="0" cellspacing="0">
         <tr>
            <td width="50%">
              <asp:Panel ID="pnlAddAddress" runat="server">
                <asp:Repeater ID="rpt1" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">

                 <HeaderTemplate>                              
                   <table width="99%" border="0" cellpadding="0" cellspacing="0">
                     <tr>
                 <td colspan="5" class="linegrey">
                       </td>
                     </tr>
                     <tr class="lgrey">
                       <td>
                           Address1
                      </td>

                       <td>
                           City
                       </td>
                        <td>
                          State
                       </td>

                       <td>
                         IsDefault
                       </td>
                       <td>
                         Actions
                      </td>
                   </tr>
                   <tr>
                     <td colspan="5" class="dots">
                   </tr>
             </HeaderTemplate>
             <ItemTemplate>
                  <tr>
                    <td>

                      <asp:LinkButton ID="lnkAddressB" runat="server" Text='<%# Eval("Address1")%>' CommandName="DisplayAddressB" CommandArgument='<%#Eval("AddID") %>' CausesValidation=false></asp:LinkButton>

                    </td>

                     <td>
                       <%# Eval("City")%>

                    </td>
                    <td>
                       <%# Eval("State")%>
                    </td>

                    <td>

                     <%-- Visible='<%# Eval("IsDefault")%>'--%>

                      <asp:LinkButton ID="lnkDefaultB" Text="Set as Default" CommandName="SetDefaultB" runat="server" CommandArgument='<%# Eval("AddID") + "," + Eval("IsB") %>'
                      CausesValidation="false" Visible='<%# Eval("IsDefault")%>'></asp:LinkButton>
                      <asp:Label ID="labelDefaultB" Text="Yes" runat="server" Visible='<%# Eval("IsDefault")%>'></asp:Label>

                    </td>
                    <td>
                     <asp:ImageButton ID="lnkAdd" CommandArgument='<%#Eval("AddID") %>'
                      CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
                      &nbsp;  
                      <asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
                      CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
                    </td>
                  </tr>
                </ItemTemplate>
                <FooterTemplate>
                </table>
                </FooterTemplate>
              </asp:Repeater>
            </asp:Panel>
           </td>
           <td>
             <asp:Panel ID="pnlSping" runat="server">
                <asp:Repeater ID="rpt12" OnItemCommand="rpt12_ItemCommand" runat="server" OnItemDataBound="rptSpping_OnItemDataBound">
                     <HeaderTemplate>
                         <table width="100%" border="0" cellpadding="0" cellspacing="0">
                             <tr>
                               <td colspan="5" class="linegrey">
                               </td>
                              </tr>
                              <tr class="lgrey">
                                 <td>
                                   Address1
                                 </td>
                                 <td>
                                   City
                                  </td>
                                  <td>
                                   State
                                   </td>
                                   <td>
                                    IsDefault
                                    </td>
                                    <td>
                                     Actions
                                     </td>
                                 </tr>
                                 <tr>
                                   <td colspan="5" class="dots">
                                  </tr>
                         </HeaderTemplate>
                         <ItemTemplate>
                                  <tr>
                                    <td>
                                       <asp:LinkButton ID="lnkAddressS" runat="server" Text='<%# Eval("Address1")%>' CommandArgument='<%#Eval("AddID") %>' CommandName="DisplayAddressS" CausesValidation="false"></asp:LinkButton>
                                     </td>

                                     <td>
                                     <%# Eval("City")%>
                                     </td>
                                     <td>
                                      <%# Eval("State")%>
                                      </td>
                                      <td>
                                        <asp:LinkButton ID="lnkDefaultS" Text="Set as Default" CommandName="SetDefaultS" runat="server" Visible=true CommandArgument='<%# Eval("AddID") + "," + Eval("IsS") %>'
                                        CausesValidation="false"></asp:LinkButton>
                                        <asp:Label ID="labelDefaultS" Text="Yes" runat="server" Visible=true></asp:Label>
                                       </td>
                                       <td>
                                        <asp:ImageButton ID="lnkAdd" Text="Edit" CommandArgument='<%#Eval("AddID") %>'
                                        CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
                                        &nbsp; 
                                        <asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
                                         CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
                                        </td>
                                       </tr>
                             </ItemTemplate>
                              <FooterTemplate>
                                 </table>
                              </FooterTemplate>
                          </asp:Repeater>
                      </asp:Panel>
                  </td>
                 </tr>
          </table>

2 个答案:

答案 0 :(得分:1)

使用css属性valign并将其值设置为顶部,如<td width="50%" valign="top">

<table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td width="50%" valign="top">
                    <asp:Panel ID="pnlAddAddress" runat="server">
                        ......
                    </asp:Panel>
                </td>
                <td valign="top">
                    <asp:Panel ID="pnlSping" runat="server">
                        ......
                    </asp:Panel>
                </td>
            </tr>
        </table>

答案 1 :(得分:1)

对于标题,请使用<th>元素,这会将它们保留在表格的顶部。

将您所拥有的<table>标记放在转发器控件之外,确保转发器只为标题呈现单行和相同的行。

除非你有充分的理由考虑将这两个表包装在<div>标签中,因为嵌套表实际上不适合布局。