动态表来编辑SQL数据库数据(可编辑表) [英] Dynamic Table to Edit SQL Database Data (Editable Table)

查看:91
本文介绍了动态表来编辑SQL数据库数据(可编辑表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



表格显示正常,并附有所有相关数据。一切都很开心!

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



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

 < asp:Repeater ID =rptPendingrunat =server> 
< HeaderTemplate>
< thead>
< tr>
< th>公司名称< / th>
< th>电话< / th>
th传真号码< / th>
< th>地址行1< / th>
< th>地址行2< / th>
City< / th>
< th>邮政编码< / th>
公司用户< / th>
< / tr>
< / thead>
< tbody>
< / HeaderTemplate>
< ItemTemplate>
< form id =formrunat =server>
< tr>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ companyName)%>>< ASP:文本框>< / TD>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ telephone)%>>< ASP:文本框>< / TD>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ faxNo)%>>< ASP:文本框>< / TD>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ addressLn1)%>>< ASP:文本框>< / TD>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ addressLn2)%>>< ASP:文本框>< / TD>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ city)%>>< ASP:文本框>< / TD>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ postCode)%>>< ASP:文本框>< / TD>
< td>< asp:TextBox ID =companyNamerunat =serverAutoPostBack =trueText =<%#Eval(_ name)%>>< ASP:文本框>< / TD>
< / tr>
< / form>
< / ItemTemplate>
< FooterTemplate>
< / tbody> < /表>
< / FooterTemplate>
< / asp:中继器>

在Old方法中,[td]标签之间的字面上只有<%#Eval (变量)%>语句。所以我把它改成了asp:Textbox标签。



我得到一个错误,说服务器标签没有正确形成。



如果有人知道一个解决方法或更好的方法,它将非常感激:)



ps没有对 asp:DataTable 或GridView的引用。我对它们并不感兴趣。 解决方案

你得到不合格错误的原因是你'在eval语句周围使用双引号,并在内部使用双引号。只需使用单引号作为周围的引号。

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

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



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


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>
                    <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.

这篇关于动态表来编辑SQL数据库数据(可编辑表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆