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
Post a Comment