开发者

Selected Index Changed event not firing for a DropDownList during databind at pageload

开发者 https://www.devze.com 2023-02-06 03:35 出处:网络
I have a Dropdownlist (System.Web.UI.WebControls.DropDownList) which I Bind during the pageload. try { if (!Page.IsPostBack)

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开发者_如何学C 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


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消