c# - Format DropDownList.TextValue -


my stored procedure this

select id, studentname xyz 

i have drop down list in asp.net, loading :

ddla.datasource = // source ddla.datatextfield = "id" + " -" + "studentname"; ddla.datavaluefield = "id"; ddla.databind(); ddla.items.insert(0, new listitem(" select one", "0")); 

but @ databind() statement, getting error:

system.web.httpexception: databinding: 'system.data.datarowview' not contain property name 'id-studentname'.

in text part of dropdown list, want display concatenated value of id - studentname.

how can it?

dropdownlist1.datatextformatstring = "{0} - {1}"; dropdownlist1.datatextfield = "id,studentname"; 

it seems it's not achievable automatically, e.g. see this ms connect ticket.


thus programmatically:

foreach (var row in table.rows) {     row.field<string>("text") = string.format(..); } 

or

foreach (var item in data) {     new listitem { text = string.format(..); };  } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -