User766369706 posted
Hi, I am currently facing a problem where i press one of the ListView item and the error:
"The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phase" appears. May i know how to solve such issue? Below are my codes
<div class="shoppingList">
<asp:ListView runat="server" ID="ListView1" GroupItemCount="5" OnPagePropertiesChanging="ListView1_PagePropertiesChanging">
<LayoutTemplate>
<table cellpadding="4" runat="server" id="tblProducts" style="height: 320px">
<tr runat="server" id="groupPlaceholder">
</tr>
</table>
<div class="pagerContent">
<asp:DataPager runat="server" ID="DataPager" PageSize="10" OnPreRender="DataPagerProducts_PreRender">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="true" ShowPreviousPageButton="true" ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" NumericButtonCssClass="btn" CurrentPageLabelCssClass="btn3" ButtonCount="3" />
<asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="true" ShowNextPageButton="true" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="productRow"
style="height: 80px">
<td runat="server" id="itemPlaceholder"></td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td valign="top" align="center" style="width: 250px" runat="server">
<asp:ImageButton ID="ProductImage" runat="server"
ImageUrl='<%# Eval("ProductImage") %>'
Height="250px" />
<br />
<asp:HyperLink ID="HyperLink1" runat="server" Text='<% #Eval("ProductName")%>'
NavigateUrl='<%#"~/ShoppingProduct.aspx?ProductID="+ Eval("ProductID")%>' />
</td>
</ItemTemplate>
</asp:ListView>
Here the method
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
ListView1.DataSource = sBLL.retrieveAllProudctAvailable();
ListView1.DataBind();
}
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
ListView1.DataSource = sBLL.retrieveAllProudctAvailable();
ListView1.DataBind();
}
protected void DataPagerProducts_PreRender(object sender, System.EventArgs e)
{
ListView1.DataBind(); <-- This where i got the error that I indicate above
base.OnPreRender(e);
}