Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a problem in getting new entered record in the listview.

HTML MARKUP

ASP.NET
<asp:ListView ID="ListView1"  InsertItemPosition="LastItem" runat="server" >

                      <LayoutTemplate>
                          <table class="table" style="text-align:left">
                              <th>ID</th>
                              <th>AcName</th>
                              <th>Naration</th>
                              <th>PaidAmount</th>
                              <th>DeductionAmount</th>
                              <th>Action</th>
                              <tr id="itemPlaceholder"  runat="server"></tr>
                          </table>
                      </LayoutTemplate>

                       <ItemTemplate>
                          <tr>
                              <td>
                                  <asp:Label runat="server" ID="lblID" Text='<%#Eval("ID") %>'></asp:Label>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblAcount" Text='<%#Eval("AcName") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblAcount" runat="server" CssClass="form-control" Text='<%#Bind("AcName") %>'></asp:TextBox>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblNaration" Text='<%#Eval("Naration") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblNaration" runat="server" CssClass="form-control" Text='<%#Bind("Naration") %>'></asp:TextBox>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblPaidAmount" Text='<%#Eval("PaidAmount") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblPaidAmount" runat="server" CssClass="form-control" Text='<%#Bind("PaidAmount") %>'></asp:TextBox>
                              </td>
                              <td>
                                  <%--<asp:Label runat="server" ID="lblDeductAmount" Text='<%#Eval("DeductionAmount") %>'></asp:Label>--%>
                                  <asp:TextBox ID="lblDeductAmount" runat="server" CssClass="form-control" Text='<%#Bind("DeductionAmount") %>'></asp:TextBox>
                              </td>

                              <td><asp:LinkButton ID="DeleteButton" cssClass="btn btn-info fa fa-trash-o" runat="server" CommandName="DeleteIt"></asp:LinkButton>


                              <%--EDIT IN THIS LINE--%>
                              <%--<asp:LinkButton ID="UpdateButton" cssClass="btn btn-info fa fa-pencil" runat="server" CommandName="UpdateIt"></asp:LinkButton>--%></td>
                              <%--EDIT IN THIS LINE--%>


                              <td>
                              </td>

                              <asp:Panel ID="Panel2" runat="server" Visible="False">
                                  <%--<asp:TextBox ID="txtEmpName" runat="server"></asp:TextBox>--%>
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label12" runat="server" Text="Credit Acount"></asp:Label>
                                                <asp:TextBox ID="txtAcName" runat="server" CssClass="form-control" Text='<%#Bind("AcName") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label13" runat="server" Text="Naration"></asp:Label>
                                                <asp:TextBox ID="txtNaration" runat="server" CssClass="form-control" Text='<%#Bind("Naration") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label14" runat="server" Text="Paid Amount"></asp:Label>
                                                <asp:TextBox ID="txtPaidAmount" runat="server" CssClass="form-control" Text='<%#Bind("PaidAmount") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="Label15" runat="server" Text="Deduction Amount"></asp:Label>
                                                <asp:TextBox ID="txtDeductAmount" runat="server" CssClass="form-control" Text='<%#Bind("DeductionAmount") %>'></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:LinkButton ID="btnUpdateRecord" cssClass="btn btn-info fa fa-check" runat="server" CommandName="UpdateRecord"></asp:LinkButton>
                                                <asp:LinkButton ID="btnCancelUpdate" cssClass="btn btn-info fa fa-close" runat="server" CommandName="CancelUpdate"></asp:LinkButton>
                                            </td>
                                        </tr>                                        
                                    </asp:Panel>
                          </tr>
                      </ItemTemplate>

                      <InsertItemTemplate>
                          <%--<tr id="Tr1"  runat="server">
                            <td>
                            </td>
                            <td>
                                <asp:TextBox ID="txtAcName" runat="server" CssClass="form-control" Text='<%#Eval("AcName") %>'
                                    Width="100px" AutoPostBack="True">Naration</asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtNaration" runat="server" CssClass="form-control" Text='<%#Eval("Naration") %>'
                                    Width="100px">Naration</asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtPaidAmount" runat="server" CssClass="form-control" onkeydown="change()" Text='<%#Eval("PaidAmount") %>'
                                    Width="100px">PaidAmount</asp:TextBox>
                            </td>
                            <td>
                                <asp:TextBox ID="txtDeductAmount" runat="server" CssClass="form-control" onkeydown="change1()" Text='<%#Eval("DeductionAmount") %>'
                                    Width="100px">DeductionAmount</asp:TextBox>
                            </td>
                            <td>
                                <asp:LinkButton ID="InsertButton" runat="server" CommandName="Add" CssClass="btn btn-info">Insert</asp:LinkButton>
                            </td>
                        </tr>--%>

                      </InsertItemTemplate>
                            
                                                                                         
                  </asp:ListView>


ON BUTTON CLICK

VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        For i As Integer = 0 To ListView1.Items.Count() - 1

            Dim txtAcNames As TextBox = TryCast(ListView1.Items(i).FindControl("txtAcName"), TextBox)

            Dim msg As String
            msg = "<script language='javascript'>"
            msg += "alert('" & txtAcNames.Text & "');"
            msg += "</script>"
            Response.Write(msg)

        Next

        'txtTotal1.Text = Paid

    End Sub


The above code works for me, The problem is when I enter data in the textbox of the listview It shows me the old values which is bind to the listview not the new value that I enter.

what I want is it should show me the new value which i entered at runtime in the lisview textbox.

I WILL BE VERY THANKFUL TO ANYONE WHO HELP ME SORT OUT THIS PROBLEM.
Posted

1 solution

I have found the answer myself I was saving duplicate values and retreiving it so if one values changes the other remains, I just remove the other markup and it worked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900