我一直在四处寻找答案,但到目前为止还没有找到解决方案。我正在尝试将 anEntityDataSource
与 GridView (C#) 一起使用。GridView 最初没有填充,Page_Load
因为我希望用户从下拉列表中选择一些信息。当用户做出一些选择并按下按钮时,我会修改 EDS 的 connectionstring 属性以使其特定于用户。这一切都很好,并且 GridView 填充了数据。
然后我尝试转到第 2 页,它工作正常。问题是当我尝试转到第 3 页时(这是任意的...我可以从 4 开始并尝试转到第 6 页...没关系)。此时,我在调试中观察并看到它EntityDataSource
是空的(TotalRowCount = 0)。我真的不想用一种non-EntityDataSource
方法重做这个,但别无选择,我会的。
我也被PageIndexChanging
解雇了,我正在尝试正确设置新索引,所以这似乎不是问题的原因......我不确定我是如何失去EntityDataSource
.
以下是部分代码:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
EntityDataSource ed2 = (EntityDataSource)this.lv2.FindControl("EntityDataSource2");
GridView gv1 = (GridView)this.lv2.FindControl("GridView1");
gv1.DataSourceID = null;
gv1.DataSource = ed2;
gv1.DataBind();
gv1.PageIndex = e.NewPageIndex;
}
<asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=MAS_CMLEntities1" DefaultContainerName="MAS_CMLEntities1" EnableFlattening="False" EntitySetName="CI_Item" AutoGenerateWhereClause="false"
Select="it.[ItemCode], it.[ItemCodeDesc], it.[LastSoldDate], it.[UDF_Manufact], it.[Category2], it.[SalesUMConvFctr], it.[DefaultWarehouseCode], it.[TotalQuantityOnHand], it.[SalesUMConvFctr]"
Where="it.[ItemCode] LIKE @siteFilter" OrderBy="it.[ItemCode]"
ViewStateMode="Inherit" onselected="EntityDataSource2_Selected">
<WhereParameters>
<asp:Parameter Name="siteFilter" Type="String" />
</WhereParameters>
</asp:EntityDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ItemCode"
DataSourceID="EntityDataSource2" CellPadding="20"
GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" CellSpacing="20" AllowPaging="True"
AllowSorting="True" onpageindexchanging="GridView1_PageIndexChanging"
onpageindexchanged="GridView1_PageIndexChanged" PageSize="15"
onrowcommand="GridView1_RowCommand">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="ItemCode" HeaderText="ItemCode" ReadOnly="True"
SortExpression="ItemCode" />
<asp:BoundField DataField="ItemCodeDesc" HeaderText="Desc" ReadOnly="True"
SortExpression="ItemCodeDesc" />
<asp:BoundField DataField="UDF_Manufact" HeaderText="MFG" ReadOnly="True"
SortExpression="UDF_Manufact" />
<asp:BoundField DataField="Category2" HeaderText="Container" ReadOnly="True"
SortExpression="Category2" />
<asp:BoundField DataField="SalesUMConvFctr" HeaderText="ContainerUOM" ReadOnly="True"
SortExpression="SalesUMConvFctr" />
<asp:BoundField DataField="DefaultWarehouseCode" HeaderText="WhseCode" ReadOnly="True"
SortExpression="DefaultWarehouseCode" />
<asp:BoundField DataField="TotalQuantityOnHand" HeaderText="QtyOnHand" ReadOnly="True"
SortExpression="TotalQuantityOnHand" />
<asp:BoundField DataField="SalesUMConvFctr" HeaderText="Units" ReadOnly="True"
SortExpression="SalesUMConvFctr" />
<asp:ButtonField ButtonType="Button" CommandName="AddToCart"
HeaderText="Add To Request" Text="Add" >
<ItemStyle HorizontalAlign="Center" />
</asp:ButtonField>
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
</asp:GridView>
我在这里做错了什么?我不明白 EDS 是如何变空的,或者我应该如何保持它的状态。