I've got my own user control inside repeater. It displays stars according to list element rating. On the first bind everything is ok, number of stars is ok for each item. Then I make a postback in which I filter this list. Then result data bind to the repeater. Lets say at first I had 5 elemetns after filtering only 3 but and only 3 are visible but the stars are in order as they were before binding.
What I would like to have is during postback each one control which is inside repeater should be recreated and appropriate number of stars whould be displayed (not the old one).
What am I doing wrong?
The repeater is inside an updatePanel.
here is my control "stars" code:
<span runat="server" id="starHolder" class="starsHolder" title="">
<input runat="server" id="star1" name="star3" type="radio" class="star1" value="1" />
<input runat="server" id="star2" name="star3" type="radio" class="star1" value="2" />
<input runat="server" id="star3" name="star3" type="radio" class="star1" value="3" />
<input runat="server" id="star4" name="star3" type="radio" class="star1" value="4"/>
<input runat="server" id="star5" name="star3" type="radio" class="star1" value="5"/>
</span>
and here is my repeater code:
<asp:Repeater EnableViewState="false" OnItemDataBound="RptrTopRated_OnDataItemBound" ID="rptrTopRated" runat="server">
<ItemTemplate>
<li class="topRated" id='<%#DataBinder.Eval(Container.DataItem, "[id]")%>'>
<p>
<%# DataBinder.Eval(Container.DataItem, "[title]") %>
</p>
<span class="ratingStar">
<cms:stars EnableViewState="false" runat="server" id="ctrlRating" McID='<%#System.Convert.ToInt32(DataBinder.Eval(Container.DataItem, "[id]"))%>' Mode="small"></cms:stars>
</span>
<a href="#" class="greenLink png" title="Leer más">Leer más</a>
</li>
</ItemTemplate>
</asp:Repeater>
It doesn't matter if enableViewsstate is set to true or false.
On ItemBound event of the repeater I even set the code:
protected void RptrTopRated_OnDataItemBound(object sender, RepeaterItemEventArgs e)
{
((stars)e.Item.FindControl("ctrlRating")).SetStarsRating();
}
which determines which input should have attrbute("checked") selected to checked:
public void SetStarsRating() {
int rate = GetRate();
this.starHolder.Attributes["title"] = McID.ToString();
if(star1.Attributes["checked"] != null) star1.Attributes.Remove("checked");
if(star2.Attributes["checked"] != null) star2.Attributes.Remove("checked");
if(star3.Attributes["checked"] != null) star3.Attributes.Remove("checked");
if(star4.Attributes["checked"] != null) star4.Attributes.Remove("checked");
if(star5.Attributes["checked"] != null) star5.Attributes.Remove("checked");
switch (rate)
{
case 1:
star1.Attributes["checked"] = "checked";
break;
case 2:
star2.Attributes["checked"] = "checked";
break;
case 3:
star3.Attributes["checked"] = "checked";
break;
case 4:
star4.Attributes["checked"] = "checked";
break;
case 5:
star5.Attributes["checked"] = "checked";
break;
}
}
During debugging I can see that code behaves in right way and sets checked attribute on good one star but there is no result in rendered HTML.