I'm having a problem with CheckBoxList and OnSelectedIndexChanged:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:CheckBoxList
id="lstWatchEType"
runat="server"
DataTextField="DescriptionText"
DataValueField="Id"
AutoPostBack="true"
OnSelectedIndexChanged="lstWatchEType_SelectedIndexChanged"/>
</ContentTemplate>
</asp:UpdatePanel>
This is populated in Page_Load (!IsPostBack)
public static void PopulateWatchEType(CheckBoxList list, Guid clientId)
{
OffertaDataContext db = new OffertaDataContext();
var ds = (from e in db.EnquiryTypes select new {
Id = e.Id,
DescriptionText = e.DescriptionText,
IsWatching = !db.WatchXrefEnquiryTypes.Any(f => f.ClientId.Equals(clientId) && f.EnquiryTypeId==e.Id && f.Inbox==false)
});
list.DataSource = ds;
list.DataBind();
foreach(var item in ds)
{
list.Items.FindByValue(item.Id.ToString()).Selected = item.IsWatching;
}
}
My problem is in:
protected void lstWatchEType_SelectedIndexChanged(Object sender, EventArgs e)
{
ListItem item = lstWatchEType.SelectedItem;
...
}
Where item is always the first element in the list???