开发者

c# Duplicate entire row in asp:table

开发者 https://www.devze.com 2023-02-20 13:27 出处:网络
campbell suggested I ask a new question for this issue so here I go. I have an ASP:Table that has one row in by default. I would like to give the user the ability to, by clicking a button, add the sa

campbell suggested I ask a new question for this issue so here I go.

I have an ASP:Table that has one row in by default. I would like to give the user the ability to, by clicking a button, add the same row again to enable more data entry. The end result being that I can commit the data开发者_运维技巧 in the rows to a SQL database.

My Table Code

<asp:Table ID="Table1" runat="server" Height="50%" Width="100%">
            <asp:TableHeaderRow CssClass="lblrow2" HorizontalAlign="Left" BackColor="AliceBlue">
                <asp:TableHeaderCell ID="haccountref">Account Ref:</asp:TableHeaderCell>
                <asp:TableHeaderCell ID="hproduct">Product</asp:TableHeaderCell>
                <asp:TableHeaderCell ID="hqty">Qty:</asp:TableHeaderCell>
                <asp:TableHeaderCell ID="hunitprice">Unit Price:</asp:TableHeaderCell>
                <asp:TableHeaderCell ID="hdiscount">Discount:</asp:TableHeaderCell>
                <asp:TableHeaderCell ID="htotal">Total Line Amount:</asp:TableHeaderCell>
            </asp:TableHeaderRow>
            <asp:TableRow CssClass="r1">
                <asp:TableCell><asp:TextBox ID="vaccountref" ReadOnly="True" runat="server"></asp:TextBox></asp:TableCell>
                <asp:TableCell><asp:DropDownList runat="server" ID="vproduct"></asp:DropDownList></asp:TableCell>
                <asp:TableCell><input id="Qty" type="text" /></asp:TableCell>
                <asp:TableCell><input id="Unit Price" type="text" /></asp:TableCell>
                <asp:TableCell><input id="Discount" type="text" /></asp:TableCell>
                <asp:TableCell><input id="Total" type="text" /></asp:TableCell>
                <asp:TableCell><input id="Button1" type="image" src="plusButton.png" value="button" /></asp:TableCell>
            </asp:TableRow>
        </asp:Table>

The question here is how would I achieve this properly and will I then be able to send the data as separate rows to SQL?

Thanks in advance

Justin


If you break the question down these are the steps you need to follow

  1. Add input fields such as Textboxes to the page which the user can fill.
  2. Add a button which will submit this new entry.
  3. In your button click handler create a new tablerow and populate it with the new data the user has supplied.
  4. When the user wants to save the table to the database you just loop through all the rows in the table and insert them.

I can elaborate further on each step but this series of steps is one way to do it and shouldn't be too difficult.

Take a look at the section in this article on adding a row to a table http://www.developerfusion.com/article/4410/in-depth-aspnet-using-adonet/4/

0

精彩评论

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