I am using the ItemCreated event to retrieve a logo from the database for any items that are added to it. The code also updates a "Point Total" for the items in the ListBox once the new item has been created. This all is working fine.
However when I step through the code I find that the ItemCreated method is getting called for all existing items in the ListBox as well as the newly added one. To make it worse it seems the ItemCreated method is called for every existing item in the ListBox whenever the SelectedIndexChanged event is raised as well. Is this normal behaviour?
Here is my ItemCreated code snippet:
And here is my ListBox declaration in the HTML:
Regards,
Andrew
However when I step through the code I find that the ItemCreated method is getting called for all existing items in the ListBox as well as the newly added one. To make it worse it seems the ItemCreated method is called for every existing item in the ListBox whenever the SelectedIndexChanged event is raised as well. Is this normal behaviour?
Here is my ItemCreated code snippet:
protected
void
listEntity_ItemCreated(
object
sender, RadListBoxItemEventArgs e)
{
RadListBox listBox = (RadListBox)sender;
RadListBoxItem item = e.Item;
LMEntityEntity entity =
new
LMEntityEntity(
int
.Parse(item.Value));
RadBinaryImage entityLogo = (RadBinaryImage)item.FindControl(
"entityLogo"
);
if
(entity.Logo.Length > 0)
entityLogo.DataValue = entity.Logo;
else
entityLogo.ImageUrl =
"~/images/faction-icons/"
+ _factionName.ToLower() +
".jpg"
;
item.DataBind();
UpdatePointTotal(listBox);
}
And here is my ListBox declaration in the HTML:
<
telerik:RadListBox
ID
=
"upgradesListBox"
runat
=
"server"
width
=
"400px"
DataKeyField
=
"LMEntityIdChild"
Height
=
"170px"
CssClass
=
"list-box"
Skin
=
"Black"
AllowDelete
=
"False"
DataValueField
=
"LMEntityIdChild"
AllowTransfer
=
"True"
TransferToID
=
"listEntityListBox"
AutoPostBack
=
"false"
AllowReorder
=
"False"
onitemdatabound
=
"upgrades_ItemDataBound"
AllowTransferDuplicates
=
"True"
AllowTransferOnDoubleClick
=
"True"
AutoPostBackOnTransfer
=
"True"
ontransferring
=
"upgrades_Transferring"
TransferMode
=
"Copy"
>
<
ItemTemplate
>
<
telerik:RadBinaryImage
id
=
"logoImage"
runat
=
"server"
CssClass
=
"list-box-icon"
DataValue='<%# (int)(Eval("LMEntity.Logo.Length"))>0?Eval("LMEntity.Logo"):null %>' height="20px" ResizeMode="Fit" width="20px" />
<
span
class
=
"list-box-text"
><
asp:Label
ID
=
"itemLabel"
runat
=
"server"
></
asp:Label
></
span
>
</
ItemTemplate
>
<
ButtonSettings
ShowTransferAll
=
"False"
TransferButtons
=
"TransferFrom"
/>
</
telerik:RadListBox
>
Regards,
Andrew