开发者

Dynamic Table to Edit SQL Database Data (Editable Table)

开发者 https://www.devze.com 2023-03-22 02:51 出处:网络
I have a Table that is generated using a SQL Database And put into a asp:Repeater to display the data.

I have a Table that is generated using a SQL Database And put into a asp:Repeater to display the data.

The table displays fine, with all relevant data. All is happy!

But The information in the table may need to be changed sometimes by the user. Rather than having a separate page or even separate section where a user can submit edits, I came up with an idea the make each CELL in the table a text box. And on page the, the text of each text box is set to the database values.

So the table will display and be EXACTLY the same, except each cell will be editable. But I'm having trouble getting it to work. What I've got so far is:

<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开发者_如何学Go>
                    <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>

In the Old method,between the [td] tags I literally just had the <%# Eval("variable") %> statement. So I changed it to the asp:Textbox tag.

I get an error saying server tag is not well formed.

If anybody knows a work around or a better method, it would be very appreciated:)

p.s. No references to asp:DataTable or GridView. I'm not interested in them.


The reason why you're getting the "not well formed" error is that you're using double quotes around the eval statement and inside them as well. Simply use single quotes as the surrounding quotes.

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

This however will not solve your overall problem of trying to edit multiple items through a repeater. If the text in any of these boxes is modified, how will you know which row this pertains to?

Have fun with what you're trying, but I suspect you will find yourself becoming interested in DataTable and GridView.

0

精彩评论

暂无评论...
验证码 换一张
取 消