c# - Where should I put new ListItem for DropDownList -


i have page 1 main dropdownlist , 2 other. made choose settings printing report.
problem - use datasources in these dropdownlists haven't empty value. should put adding new empty value dropdownlist correct work?
there code (in comment thing need add)

protected void ddlmain_load(object sender, eventargs e) {     switch (ddlmain.selectedvalue)     {         case "1":             dfirst.visible = true;             dsecond.visible = false;             break;         case "2":             dfirst.visible = false;             dsecond.visible = true;             break; }  <div> <asp:dropdownlist id="ddlmain" runat="server" autopostback="true" onload="ddlmain_load">     <asp:listitem text="1" value="1"></asp:listitem>     <asp:listitem text="2 " value="2"></asp:listitem> </asp:dropdownlist>               </div>  <div runat="server" id="dfirst" visible="false">     <asp:dropdownlist id="ddlfirst" runat="server" datasourceid="sdsfirst"         datatextfield="name" datavaluefield="id" onload="ddlfirst_load">     </asp:dropdownlist>     <asp:sqldatasource id="sdsfirst" runat="server"          connectionstring="<%$ connectionstrings:constr %>">     </asp:sqldatasource> </div> //ddlfirst.items.add(new listitem("--select--", "-1")); 

i tried onload secondary element, onload main dropdownlist , page_load. don't fit me because new listitem don't appears when page firstly loading or added more 1 time when page refreshes.

use insert method in page load.

ddlacademicyear.items.insert(0, new listitem("-- select --", "-1")); 

0 position @ want insert.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -