ASP.net Listview不显示当前行值 [英] ASP.net Listview dont show current row value

查看:70
本文介绍了ASP.net Listview不显示当前行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我在列表视图中输入新记录时遇到问题。



HTML MARKUP



Hi I have a problem in getting new entered record in the listview.

HTML MARKUP

<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





ON BUTTON CLICK

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.



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.

推荐答案

I have found the answer myself I was saving dupl icate values and retreiving it so if one values changes the other remains, I just remove the other markup and it worked.
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.


这篇关于ASP.net Listview不显示当前行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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