c# - Display two data fields' content in dropdownlist then hide one on clicking -


so want when click dropdown shows 2 items dropdownlist. left side show id , right side show text.

so (98739 | smoker) when click onto item want dropdown list show "smoker"

i have tried

 string sqlgetclass = "select [code], [snomedcode] + ' | ' + [descrip] [fulldescrip] lt__smokingstatus";         sqlcommand cmdsmoke = new sqlcommand(sqlgetclass, con);         con.open();         sqldataadapter da = new sqldataadapter(cmdsmoke);         dataset ds = new dataset();         da.fill(ds);         ddlsmokestat.datasource = ds;         ddlsmokestat.datatextfield = "fulldescrip";         ddlsmokestat.datavaluefield = "code";         ddlsmokestat.databind();         con.close(); 

that works fine , shows (98739 | smoker) in dropdown. wondering anyway of hiding 98739 code there after have selected item. know setting , calling that. other way combine them wish?

first, i've made editing title clarify task (you not hiding other items in list, part of selected item).

based on assumption, straightforward solution re-query same control modified select sql statement like: "select [code], [descrip] lt__smokingstatus" , correspondingly modify datatextfield binding like: ddlsmokestat.datatextfield = "descrip";

also, need persist selected item between post-backs (for example, in session variable) , show selected after binding. otherwise, can implement partial/conditional web page rendering via microsoft ajax (use updatepanel , specify dropdown trigger events).

there more efficient solutions (for example, store content of data fields in list or array, or dictionary , bind dropdown control data structure, described in article: binding-asp-net-dropdownlist), requires substantial code modification.

also, task can accomplished using javascript code snippets on html select element rendered asp.net drop-down control, solution won't work if javascript disabled on client's computer.

hope may help. best regards,


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -