raven_977
raven_977

Reputation: 475

How to write ListView TextBox Items to Database for each row

I have this Listview:

<asp:ListView ID="fundingListView" runat="server" OnItemCommand="fundingListView_OnItemCommand" OnItemDataBound="fundingListView_OnItemDataBound" DataKeyNames="ID"> 
                    <ItemTemplate>
                        <div style="width:40px; float:left; margin:5px 15px 5px 0px; padding-left:10px;">
                            <asp:LinkButton ID="addFundingLinkButton" runat="Server" ToolTip="Finanzierung zuweisen" CommandName="addFunding" CssClass="insertTextModuleButtonFade"></asp:LinkButton>
                        </div>
                        <div style="float:left; width:40px; margin:10px 10px 5px 0px; text-align:center;"><%# Eval("id") %>&nbsp;</div>
                        <div style="float:left; width:120px; margin:10px 10px 5px 0px; text-align:center;"><%# Eval("financialPartnerId") %>&nbsp;</div>
                        <div style="float:left; width:80px; margin:10px 10px 5px 0px; text-align:center;"><%# Eval("accountNumber") %>&nbsp;</div>
                        <div style="float:left; width:120px; margin:10px 10px 5px 0px; text-align:center;"><%# Eval("fundingAmount") %></div>                    
                        <div style="float:left; width:120px; margin-left:40px;">
                            <asp:TextBox ID="fundingConfirmationAmount" runat="server" Width="96" Height="12"></asp:TextBox>
                        </div>     
                        <asp:Label id="fundingAlreadyAddedButton" runat="server" style="visibility:hidden"><%# Eval("alreadyAdded") %></asp:Label>               
                        <div class="clear"></div>
                    </ItemTemplate>

It is possible to change the value of the textbox "fundingConfirmationAmount" on the webpage.

How do I access the entered value in this textbox for each row of the listview and write the new text to my mysql database?

Thanks in advance

Upvotes: 1

Views: 249

Answers (1)

JoshuadV
JoshuadV

Reputation: 194

You can try this, have no chance to test if the control is found.

List<ListViewDataItem> lItems = fundingListView.Items.ToList();

        foreach(ListViewDataItem item in lItems)
        {
            TextBox tb = item.FindControl("fundingConfirmationAmount") as TextBox;
            string addToDatabase = tt.Text;

        }

Upvotes: 2

Related Questions