c# - Select first letter of name with linq query from database -
i want select first letter of name , change font-weight following code;
var selectlist = db.users.select(x => x.name.substring(0,1)).firstordefault(); tellist.items.clear(); (int = 0; < alpha.length; i++) { listitem listitem = new listitem(convert.tostring(alpha[i])); listitem.attributes.add("value", convert.tostring(i)); if (selectlist == s) { listitem.attributes.add("class", "class2"); } else { listitem.attributes.add("class", "class1"); } tellist.items.add(listitem); }
var s = db.users.select(x => x.name.substring(0,1)).firstordefault(); tellist.items.clear(); (int = 0; < alpha.length; i++) { var listitem = new listitem(convert.tostring(alpha[i])); listitem.attributes.add("value", convert.tostring(i)); if (convert.tostring(i) == s) { listitem.attributes.add("class", "class2"); } else { listitem.attributes.add("class", "class1"); } tellist.items.add(listitem); } alternatively:
var s = db.users.select(x => x.name.substring(0,1)).firstordefault(); tellist.items.clear(); tellist.attributes.add("data-firstletter",s); tellist.items.addrange(alpha.select((letter,index)=>new listitem(letter,index.tostring())); then use css style listitem (assuming select has id tellist):
#tellist > li { font-weight: normal; } #tellist[data-firstletter=a] > li[value=0], #tellist[data-firstletter=b] > li[value=1], #tellist[data-firstletter=c] > li[value=2], #tellist[data-firstletter=d] > li[value=3], #tellist[data-firstletter=e] > li[value=4], #tellist[data-firstletter=f] > li[value=5], ... #tellist[data-firstletter=z] > li[value=25] { font-weight: bold; }
Comments
Post a Comment