【问题标题】:Dynamic Table to Edit SQL Database Data (Editable Table)用于编辑 SQL 数据库数据的动态表(可编辑表)
【发布时间】:2011-10-10 02:43:18
【问题描述】:

我有一个使用 SQL 数据库生成的表并放入 asp:Repeater 以显示数据。

表格显示良好,包含所有相关数据。万事如意!

但有时用户可能需要更改表格中的信息。我没有使用单独的页面甚至单独的部分供用户提交编辑,而是提出了一个想法,即让表格中的每个 CELL 成为一个文本框。并且在页面上,每个文本框的文本都设置为数据库值。

所以表格将显示并且完全相同,除了每个单元格都是可编辑的。但我无法让它工作。到目前为止我得到的是:

<asp:Repeater ID="rptPending" runat="server">
    <HeaderTemplate>
        <table id="tblPending" cellpadding="0" cellspacing="0" border="0" class="display">
            <thead>
                <tr>
                    <th>Company Name</th>
                    <th>Telephone</th>
                    <th>Fax Number</th>
                    <th>Address Line 1</th>
                    <th>Address Line 2</th>
                    <th>City</th>
                    <th>Postcode</th>
                    <th>Company User</th>
                </tr>
            </thead>
            <tbody>
    </HeaderTemplate>
    <ItemTemplate>
        <form id="form" runat="server">
            <tr>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_companyName") %>"></asp:TextBox></td>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_telephone")%>"></asp:TextBox></td>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_faxNo")%>"></asp:TextBox></td>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_addressLn1")%>"></asp:TextBox></td>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_addressLn2")%>"></asp:TextBox></td>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_city")%>"></asp:TextBox></td>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_postCode")%>"></asp:TextBox></td>
                <td><asp:TextBox ID="companyName" runat="server" AutoPostBack="true" Text="<%# Eval("_name")%>"></asp:TextBox></td>
            </tr>
        </form>
    </ItemTemplate>
    <FooterTemplate>
        </tbody> </table>
    </FooterTemplate>
</asp:Repeater>

在旧方法中,在 [td] 标记之间,我实际上只有 语句。于是我把它改成了asp:Textbox标签。

我收到一条错误消息,提示服务器标签格式不正确。

如果有人知道解决方法或更好的方法,将不胜感激:)

附言没有对 asp:DataTable 或 GridView 的引用。我对它们不感兴趣。

【问题讨论】:

    标签: html asp.net html-table


    【解决方案1】:

    您收到“格式不正确”错误的原因是您在 eval 语句及其内部使用了双引号。只需使用单引号作为周围的引号。

    <td>
       <asp:TextBox 
           ID="companyName" 
           runat="server" 
           AutoPostBack="true" 
           Text='<%# Eval("_companyName") %>'
        >
       </asp:TextBox>
     </td>
    

    但是,这并不能解决您尝试通过转发器编辑多个项目的整体问题。如果这些框中的任何一个文本被修改,您如何知道这属于哪一行?

    玩得开心,但我怀疑你会发现自己对 DataTable 和 GridView 感兴趣。

    【讨论】:

    • 哈哈,别误会,dataTable 和 Grid View 非常有用,但我目前正在使用 jquery 数据表...我确信我的想法会失败,但认为它可能值得一试。如果我想出一个解决方案,我会发布它:)
    猜你喜欢
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-04
    • 1970-01-01
    • 2016-11-25
    相关资源
    最近更新 更多