I have a Dropdownlist (System.Web.UI.WebControls.DropDownList) which I Bind during the pageload.
try
{
if (!Page.IsPostBack)
{
DataTable dt = new StaticNoticeController().GetStaticNoticeNames();
this.HeadingsDropDownList.AutoPostBack = true;
this.HeadingsDropDownList.DataSource = new StaticNoticeController().GetStaticNoticeNames();
this.HeadingsDropDownList.DataTextField = "NoticeName";
this.HeadingsDropDownList.DataValueField = "NoticeId";
this.HeadingsDropDownList.DataBind();
}
}
catch (SystemException ex)
{
//ToDo: Log the Exception
}
I expect the SelectedIndex event to get fired when I bind the dropdown to a combobox ( which use to happen in case of Comboboxes in Winforms ) so that the page is loaded with values corresponding to the initial value in the dropdown list.
I even tried
this.HeadingsDropDownList.selectedIndex = -1;
in pageload after databind. But in vain .
When I change the index of the dropdown through the browser , the event gets fired as usual. Am I missing something or am I trying to perform something which is not possible ?
Please help. Thanks in Advance
Why do you want to fire the SelectedIndexChanged-Event?? As you have already mentioned, the selected index will change if the user changes it manually on client-side. This is the desired behaviour. If you initially want to call a function on serverside that would be also called when the selected index changes, call it manually!
It would essentially mean that when you load the site it would directly postback. It would be stuck in a loop.
If its an inited value, then what the postback would do should be done in the init.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.