c# - How to add a Default text on Drop Down List? -


i'm having hard time adding default text drop down list. want have default "select department..." text drop down list. text has no value @ , never add database when selected. display, instruction user.


void getusertypes() {     con.open();     sqlcommand cmd = new sqlcommand();     cmd.connection = con;     cmd.commandtext = "select typeid, typename types";     sqldatareader dr = cmd.executereader();     ddltypes.datasource = dr;     ddltypes.datatextfield = "typename";     ddltypes.datavaluefield = "typeid";     ddltypes.databind();     con.close(); } 

    <!--department-->     <div class="form-group">         <label class="control-label col-lg-4">             department</label>         <div class="col-lg-8">             <asp:dropdownlist id="ddltypes" runat="server" class="form-control" />         </div>     </div> 

i have tried adding appenddatabounditems problem when submit form having selected item of drop down list "select department..." have error.

how adding listitem directly in mark up, such as:

<asp:dropdownlist runat="server" id="ddltypes" appenddatabounditems="true">     <asp:listitem text="select value..." value="0" selected="true"></asp:listitem> </asp:dropdownlist> 

make sure appenddatabounditems="true" present though. , in event listener or validation, check dlltypes.selectedvalue != 0.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -