ASP.Net中的表

时间:2012-07-12 23:07:24

标签: asp.net html markup

我正在使用ASP.net创建我的第一个网站,并且在格式化表格时遇到了一些问题。我希望能够让用户填写调查问卷。这是一个多部分的调查问卷,因此我使用手风琴来节省空间。第一个窗格中的一个问题有五个部分的答案。我的桌子给了我一些意想不到的行为。大约一半我尝试在五个文本框上方显示五个标签。我将它们插入表中的正确位置,但由于某种原因它们出现在页面的底部。我无法确定发生了什么。有任何想法吗?提前谢谢。

<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Questionnaire.aspx.cs" Inherits="About" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <style type="text/css">
        .accordion
        {
            width: 950px;
        }

        .accordionHeader
        {
            border: 1px solid #2F4F4F;
            color: white;
            background-color: #2E4d7B;
            font-family: Arial, Sans-Serif;
            font-size: 12px;
            font-weight: bold;
            padding: 5px;
            margin-top: 5px;
            cursor: pointer;
        }
        .accordionHeaderSelected
        {
            border: 1px solid #2F4F4F;
            color: white;
            background-color: #5078B3;
            font-family: Arial, Sans-Serif;
            font-size: 12px;
            font-weight: bold;
            padding: 5px;
            margin-top: 5px;
            cursor: pointer;
        }

        .accordionContent
        {
            background-color: #D3DEEF;
            border: 1px dashed #2F4F4F;
            border-top: none;
            padding: 5px;
            padding-top: 10px;
        }

        .style1
        {
            width: 100%;
        }
    </style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Questionnaire
    </h2>
    <p>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    </p>
    <p>
    </p>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Accordion ID="Accordion1" CssClass="accordion" HeaderCssClass="accordionHeader"
                HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent"
                runat="server" Height="100px" Width="950px">
                <Panes>
                    <asp:AccordionPane ID="AccordionPane2" runat="server">
                        <Header>
                            General Business & Project Question</Header>
                        <Content>
                            <table class="style1">
                                <tr>
                                    <asp:Label ID="lblQid2_1" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_1" runat="server"></asp:Label>
                                </tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_1" runat="server"></asp:TextBox></tr>
                                <tr>
                                    <asp:Label ID="lblQid2_2" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_2" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_2" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_3" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_3" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_3" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_4" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_4" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_4" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_5" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_5" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_5" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_5_1" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_5_1" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_5_1" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_5_2" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_5_2" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_5_2" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_5_3" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_5_3" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_5_3" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_6" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_6" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_6" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_7" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_7" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_7" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_8" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_8" runat="server"></asp:Label></tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="Label1"  Text="test" runat="server"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="Label2" runat="server"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="Label3" runat="server"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="Label4" runat="server"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="Label5" runat="server"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="txtQ2_8" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_9" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_9" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txt2_9" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_10" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_10" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:TextBox ID="txtQ2_10" runat="server"></asp:TextBox>
                                </tr>
                                <tr>
                                    <asp:Label ID="lblQid2_11" runat="server"></asp:Label>
                                    <asp:Label ID="lblQ2_11" runat="server"></asp:Label></tr>
                                <tr>
                                    <asp:RadioButton ID="rboQ2_11y" Text="Yes" runat="server" AutoPostBack="True" GroupName="a"
                                        OnCheckedChanged="rboQ2_11y_CheckedChanged" />
                                    <asp:RadioButton ID="rboQ2_11n" Text="No" runat="server" AutoPostBack="True" GroupName="a"
                                        OnCheckedChanged="rboQ2_11n_CheckedChanged" /></tr>
                                <tr>
                                    <asp:Label ID="lblQid2_11_1" runat="server"></asp:Label>
                                    <asp:TextBox ID="txtQ2_11_1" runat="server"></asp:TextBox>
                                </tr>
                            </table>
                        </Content>
                    </asp:AccordionPane>
                    <asp:AccordionPane ID="AccordionPane3" runat="server">
                        <Header>
                            Solution Architecture & Technical Questions</Header>
                        <Content>
                            <table class="style1">
                                <tr>
                                    <asp:CheckBox ID="chb_1" runat="server" Text="Testing" /></tr>
                            </table>
                        </Content>
                    </asp:AccordionPane>
                </Panes>
            </asp:Accordion>
        </ContentTemplate>
    </asp:UpdatePanel>
    <p>
        <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
        <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
    </p>
    <p>
</asp:Content>

2 个答案:

答案 0 :(得分:3)

你需要解决这个问题:

<tr>
    <asp:Label ID="lblQid2_1" runat="server"></asp:Label>
    <asp:Label ID="lblQ2_1" runat="server"></asp:Label>
</tr>

对于每行,您都有<tr>个标记:

<tr>
    <td>
        <asp:Label ID="lblQid2_1" runat="server"></asp:Label>
        <asp:Label ID="lblQ2_1" runat="server"></asp:Label>
    <td>
</tr>

或者这取决于您需要的每行(<td>)列数(<tr>):

<tr>
    <td>
        <asp:Label ID="lblQid2_1" runat="server"></asp:Label>
    </td>
    <td>
        <asp:Label ID="lblQ2_1" runat="server"></asp:Label>
    <td>
</tr>

希望它有所帮助!

答案 1 :(得分:2)

你的html表格有<tr> table rows but no <td> table columns这可能是你的标签和文本框在页面底部移动的原因