我正在尝试添加以下网格视图的可变行, 例如,如果我选择5,编译器称为GetAllProducts 5次。 如何避免这种情况并一次调用GetAllProducts 实际上每个RadComboBox都有超过50000,所以我也需要远离以避免内存异常。 那么,如何避免每个新行的呼叫数据源功能
<asp:GridView ID="gvPOAdd" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="gvPOAdd_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="" />
<asp:TemplateField HeaderText="SKU [ Product Name ]">
<ItemTemplate>
<asp:ObjectDataSource ID="odsSKU" runat="server" TypeName="DotShoppingCart.Commercial.Core.Product" SelectMethod="GetAllProducts " />
<telerik:RadComboBox ID="rcbSKU" runat="server" Text='<%#Eval("SKU") %>' CausesValidation="false" EmptyMessage="Type an SKU" DataSourceID="odsSKU" MarkFirstMatch="true" AutoCompleteSeparator=";" Width="550px" data OnSelectedIndexChanged="rcbSKU_SelectedIndexChanged"></telerik:RadComboBox>
<br />
<asp:RequiredFieldValidator runat="server" ID="rfvSKU" ControlToValidate="rcbSKU" ErrorMessage="SKU Required" ValidationGroup="ProductRequired" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
private void SetInitialRow()
{
int numberOfRows =1;
if(NumberOflinesTextbox.Text!="" && int.Parse(NumberOflinesTextbox.Text.ToString())>0)
numberOfRows=int.Parse(NumberOflinesTextbox.Text.ToString());
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("SKU", typeof(string)));
dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
dt.Columns.Add(new DataColumn("UnitCost", typeof(string)));
dt.Columns.Add(new DataColumn("TotalCost", typeof(string)));
for (int i = 1; i <= numberOfRows; i++)
{
dr = dt.NewRow();
dr["RowNumber"] = i;
dr["SKU"] = string.Empty;
dr["Quantity"] = string.Empty;
dr["UnitCost"] = string.Empty;
dr["TotalCost"] = string.Empty;
dt.Rows.Add(dr);
}
Session["CurrentPoTable"] = dt;
gvPOAdd.DataSource = dt; //I think here Compiler get into GetAllProducts for 5 times
gvPOAdd.DataBind();
}
我正在考虑会议?!任何想法或代码都可以帮助我..