用于编辑SQL数据库数据的动态表(可编辑表)

问题描述 投票:0回答:1

我有一个使用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>

在Old方法中,在[td]标签之间,我实际上只有<%#Eval(“variable”)%>语句。所以我把它改成了asp:Textbox标签。

我收到一条错误,说服务器标签格式不正确。

如果有人知道一个工作或更好的方法,将非常感谢:)

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

html asp.net html-table
1个回答
1
投票

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

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

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

享受你正在尝试的东西,但我怀疑你会发现自己对DataTable和GridView感兴趣。

© www.soinside.com 2019 - 2024. All rights reserved.