c# - dropdownlist in header template of repeater not working -


i have set think correct markup , code behind put dropdownlist in header template of repeater, yet reason, it's not working correctly. see dropdown list, when make selection in list, onselectedindexchanged event not seem trigger use of method added handle , can't figure out i'm missing, thought straightforward thing.

here essentials of markup:

<asp:repeater id="repnewsitems" runat="server"> <headertemplate>         <asp:dropdownlist id="dddatesortcategories" runat="server" width="200" autopostback="true" onselectedindexchanged="dddatesortcategories_selectedindexchanged1" cssclass="mergersdropdown">             <asp:listitem selected="true" text="most recent" value="newest"></asp:listitem>             <asp:listitem text="oldest" value="oldest"></asp:listitem>         </asp:dropdownlist> </headertemplate>  <itemtemplate>     // other stuff 

and here guts of code behind:

    [macroparameter(macroparametertype.number)]     public int pageid { get; set; }      public string _category = "";      protected void page_load(object sender, eventargs e)     {         if (repnewsitems == null) return;          _category = request.querystring["category"];          repnewsitems.itemdatabound += new repeateritemeventhandler(repnewsitems_itemdatabound);          repnewsitems.datasource = (string.isnullorempty(newsnodeids))                                         ? getnewsitemsforyear(newsyeartodisplay, _category)                                         : danews;         repnewsitems.databind();     }      protected void dddatesortcategories_selectedindexchanged1(object sender, eventargs e)     {         dropdownlist ddl = (dropdownlist)(sender);         response.redirect(umbraco.library.niceurl(pageid) + "?category=" + server.urlencode(ddl.selectedvalue.tostring()));     }      void repnewsitems_itemdatabound(object sender, repeateritemeventargs e)     {          if (e.item.itemtype == listitemtype.header)         {             dropdownlist ddl = (dropdownlist)e.item.findcontrol("dddatesortcategories");             if (!ispostback)             {                 if (ddl != null)                 {                     ddl.datasource = getnewsitemsforyear(documenttypes.newsitem.getmostrecentyear(newscategorytodisplay).tostring(), _category);                     ddl.databind();                 }             }             if (!string.isnullorempty((request.querystring["category"]))) ddl.text = request.querystring["category"];         }         // other stuff      } 

i found 2 issues code above. first, mistakenly binding list items dropdownlist, meant have hard-coded list items wouldn't change. didn't fix main issue, though. did was forgetting wrap these:

repnewsitems.itemdatabound += new repeateritemeventhandler(repnewsitems_itemdatabound); repnewsitems.datasource = (string.isnullorempty(newsnodeids))                                     ? getnewsitemsforyear(newsyeartodisplay, _category)                                     : danews; repnewsitems.databind(); 

in

if (!ispostback) {}  

conditional statement. meant each time postback event fired, enter page_load method, rebind entire repeater in initial state , never let pass through selectedindexchanged event handler dddatesortcategories_selectedindexchanged1.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -