如何在ASP.NET中添加/读取项目 [英] How to add/read items in ASP.NET

查看:50
本文介绍了如何在ASP.NET中添加/读取项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置的文本框,用户可以在其中输入内容,当他们单击提交"时,我会使用它们.我需要添加一个按钮,让他们即时添加另一组相同的文本框,然后在其中输入数据,然后在按下提交按钮时,我需要从这两组文本框中获取值.添加的项目集数量可以是无限的.

I have a set textboxes where the user enters something and I use them when they click Submit. I need to add a button that lets them add another identical set of textboxes on the fly, enter data into those and then when the submit button is pressed I need to grab the value from both sets. The amount of added sets of items can be unlimited.

在ASP.NET/C#中处理此类内容的最佳方法是什么?

What's the best way to handle something like this in ASP.NET/C#?

我环顾四周,基本上只知道您可以尝试在前端使用JQuery,这会使后端一团糟,或者您可以尝试使用GridView并每次将其与可能会造成混乱的新项目重新绑定

I've looked around and have basically only gotten that you can try to use JQuery on the front end which leaves the backend a mess or you can try to use a GridView and rebind it every time with new items which can get messy.

有什么更好/更容易的方法吗?

Any better/easier way to do this?

感谢您的帮助.

推荐答案

对第一组文本框使用Repeater控件,并在每个额外的列表中重复该控件.

Use a Repeater control for the first set of text boxes, and have it repeat for each extra listing.

这是我的评论控制中继器.这有点奥秘,因为它是我在asp.net中进行的第一个控制,但是它应该可以带您进入.

Here's my comment control repeater. It's a little arcane, as it was the first control I ever made in asp.net, but it should get you going.

<asp:Repeater runat="server" ID="repeater" 
  onitemdatabound="repeater_ItemDataBound"
  >
  <HeaderTemplate>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
  </HeaderTemplate>  
  <FooterTemplate>
    </table>
  </FooterTemplate>
  <ItemTemplate>
    <tr id="trContents" runat="server"><td>
      <table id="tableComment" runat="server"
        width="100%" style="border-color:Black; border-width:1px; border-style:solid;background-color:#EEEE99">
        <tr><td id="tdHeader" runat="server"
           style="border-color:Black; border-width:1px; border-style:solid;padding: 5px">
          <table width="100%" id="tableHeader" runat="server">
            <tr>
              <td>
                <asp:Label ID="headerText" runat="server" 
                  Text="<%# GetHeader((CommentRecord)Container.DataItem) %>" />
              </td>
              <td style="text-align:right"> <%-- OnClientClick="aspnetForm.target ='_blank';"  --%>
                <asp:Button ID="btnEdit" runat="server" Text="Edit" 
                    PostBackUrl="<%$ AppSettings:TextEditor %>"  
                    />
                <asp:Button ID="btnReply" runat="server" Text="Reply" 
                    PostBackUrl="<%$ AppSettings:TextEditor %>"  
                    />
              </td>
            </tr>
          </table>
        </td></tr>
        <tr><td style="border-color:Black; border-width:1px; border-style:solid;background-color:#FFFFF0;padding: 10px">
            <%# ((CommentRecord)Container.DataItem).Text %>
        </td></tr>
        <tr><td>
          <table width="100%"><tr>
            <td style="text-align:left">
                <asp:Button ID="btnDelete" runat="server" Text="Delete" 
                    CausesValidation="False" />
            </td>
            <td style="text-align:right">
              <asp:Label ID="footer" runat="server" Text="<%# GetFooter((CommentRecord)Container.DataItem) %>" />
            </td>
          </tr></table>
        </td></tr>
      </table>
      <asp:PlaceHolder ID="placeHolder" runat="server" />
    </td></tr>
  </ItemTemplate>
</asp:Repeater>

这篇关于如何在ASP.NET中添加/读取项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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