Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的asp.net listview不显示最新插入的记录?_Asp.net_Listview_Sqldatasource - Fatal编程技术网

为什么我的asp.net listview不显示最新插入的记录?

为什么我的asp.net listview不显示最新插入的记录?,asp.net,listview,sqldatasource,Asp.net,Listview,Sqldatasource,我只是试着去适应LVs,我只是把它放在一起。我的印象是LV会在插入后处理LV的插入和刷新,但事实并非如此。我甚至添加了LV.rebind(),但仍然一无所获 我让LV在第一次插入后正确刷新/重新绑定,但后续插入不会产生刷新的LV。我已确认记录已正确插入数据库 这是到目前为止我的代码,是吗 <asp:ListView ID="ListView1" runat="server" DataKeyNames="ProductID" EnableViewState="true" datas

我只是试着去适应LVs,我只是把它放在一起。我的印象是LV会在插入后处理LV的插入和刷新,但事实并非如此。我甚至添加了LV.rebind(),但仍然一无所获

我让LV在第一次插入后正确刷新/重新绑定,但后续插入不会产生刷新的LV。我已确认记录已正确插入数据库

这是到目前为止我的代码,是吗

<asp:ListView ID="ListView1" runat="server" DataKeyNames="ProductID" EnableViewState="true" 
    datasourceid="sqlDS" InsertItemPosition="LastItem">
    <AlternatingItemTemplate>
        <tr style="">
            <td>
            </td>
            <td>
                <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
            </td>
            <td>
                <asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>' />
            </td>
            <td>
                <asp:Label ID="DescriptionLabel" runat="server" 
                    Text='<%# Eval("Description") %>' />
            </td>
            <td>
                <asp:Label ID="CostLabel" runat="server" Text='<%# Eval("Cost") %>' />
            </td>
        </tr>
    </AlternatingItemTemplate>
    <EditItemTemplate>
        <tr style="">
            <td>
                <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                    Text="Update" />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                    Text="Cancel" />
            </td>
            <td>
                <asp:Label ID="ProductIDLabel1" runat="server" 
                    Text='<%# Eval("ProductID") %>' />
            </td>
            <td>
                <asp:TextBox ID="CategoryTextBox" runat="server" 
                    Text='<%# Bind("Category") %>' />
            </td>
            <td>
                <asp:TextBox ID="DescriptionTextBox" runat="server" 
                    Text='<%# Bind("Description") %>' />
            </td>
            <td>
                <asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
            </td>
        </tr>
    </EditItemTemplate>
    <EmptyDataTemplate>
        <table runat="server" style="">
            <tr>
                <td>
                    No data was returned.</td>
            </tr>
        </table>
    </EmptyDataTemplate>
    <InsertItemTemplate>
        <tr style="">
            <td>
                <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                    Text="Insert" />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                    Text="Clear" />
            </td>
            <td>
                &nbsp;</td>
            <td>
                <asp:TextBox ID="CategoryTextBox" runat="server" 
                    Text='<%# Bind("Category") %>' />
            </td>
            <td>
                <asp:TextBox ID="DescriptionTextBox" runat="server" 
                    Text='<%# Bind("Description") %>' />
            </td>
            <td>
                <asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
            </td>
        </tr>
    </InsertItemTemplate>
    <ItemTemplate>
        <tr style="">
            <td>
            </td>
            <td>
                <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
            </td>
            <td>
                <asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>' />
            </td>
            <td>
                <asp:Label ID="DescriptionLabel" runat="server" 
                    Text='<%# Eval("Description") %>' />
            </td>
            <td>
                <asp:Label ID="CostLabel" runat="server" Text='<%# Eval("Cost") %>' />
            </td>
        </tr>
    </ItemTemplate>
    <LayoutTemplate>
        <table runat="server">
            <tr runat="server">
                <td runat="server">
                    <table ID="itemPlaceholderContainer" runat="server" border="0" style="">
                        <tr runat="server" style="">
                            <th runat="server">
                            </th>
                            <th runat="server">
                                ProductID</th>
                            <th runat="server">
                                Category</th>
                            <th runat="server">
                                Description</th>
                            <th runat="server">
                                Cost</th>
                        </tr>
                        <tr ID="itemPlaceholder" runat="server">
                        </tr>
                    </table>
                </td>
            </tr>
            <tr runat="server">
                <td runat="server" style="">
                    <asp:DataPager ID="DataPager1" runat="server">
                        <Fields>
                            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                ShowLastPageButton="True" />
                        </Fields>
                    </asp:DataPager>
                </td>
            </tr>
        </table>
    </LayoutTemplate>
</asp:ListView>


<asp:SqlDataSource ID="sqlDS" runat="server" 
        DataSourceMode="DataSet" EnableCaching="true"                
        ConnectionString="<%$ ConnectionStrings:ProjectDashboardConnectionString %>" 
        SelectCommand="usp_CafeteriaGetProducts" SelectCommandType="StoredProcedure" 
        FilterExpression="Category='A'"            
        InsertCommand="usp_CafeteriaInsertProducts" InsertCommandType="StoredProcedure">
    <InsertParameters>
        <asp:Parameter Name="Description" Type="String" />
        <asp:Parameter Name="Category" Type="String" />
        <asp:Parameter Name="Cost" Type="Decimal" />
    </InsertParameters>
</asp:SqlDataSource>

有什么想法吗?
谢谢。

这是因为sqldatasource属性EnableCaching被设置为“true”。已完全删除该属性,因为默认值为False

Public Class WebForm3
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub ListView1_ItemInserted(ByVal sender As Object, ByVal e As ListViewInsertedEventArgs) Handles ListView1.ItemInserted

    sqlDS.Dispose()
    sqlDS.DataBind()

    ListView1.Dispose()
    ListView1.DataSourceID = "sqlDS"
    ListView1.DataBind()


End Sub

Protected Sub sqlProducts_ItemInserting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs) Handles sqlDS.Inserting
    ''Do something

End Sub


Protected Sub sqlProducts_ItemInserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs) Handles sqlDS.Inserted
    ''Do something

End Sub
End Class