To fix this issue You should be able to call dlstSelectedImages.SelectedIndex at any time to get the currently selected index. It doesn't have to reside in an SelectedIndexChanged event handler. SelectedIndex is zero based and its default value is -1. The SelectedIndexChanged event fires whenever the selected index changes (i.e. whenever SelectedIndex is assigned a new value). Typically, this would be on an ItemCommand or some other event:
void Item_Command(Object sender, DataListCommandEventArgs e)
// Set the SelectedIndex property to select an item in the DataList.
dlstSelectedImages.SelectedIndex = e.Item.ItemIndex;
// Rebind the data source to the DataList to refresh the control.
ASP.NET C# DataList - Find Hidden Field in Child DataList
will be helpful for those in need You can use the NamigContainer property to get the DataListItem, then use FindControl:
protected void chkChildCompany_CheckedChanged(object sender, EventArgs e)
var chk = (CheckBox) sender;
var item = (DataListItem) chk.NamingContainer;
var hiddenCompanyID = (HiddenField) item.FindControl("hiddenCompanyID");
// here you are ...