Split String and add in combobox in c# -
im getting data database , adding combobox.the string contains list of names comma.
datarow dr = newdt.rows[i]; traineecombo.items.add(dr["trainee"].tostring());
it works fine want split string , add each item combobox. tried below methods.
datarow dr = newdt.rows[i]; string temptr = dr["trainee"].tostring(); string[] result = temptr.split(new char[] {','}); foreach (string s in result) { if (s.trim() != "") traineecombo.items.add(s); }
second method:
string temptr = dr["trainee"].tostring(); traineecombo.items.addrange(temptr.split(','));
but both methods shows error
cannot convert string char[] , invalid arguments. got piece of sample code msdn.how can solve it?
try this
datarow dr = newdt.rows[i]; string temptr = dr["trainee"].tostring(); string[] result = temptr.split(','); foreach (string s in result) { if (s.trim() != "") traineecombo.items.add(s); }
Comments
Post a Comment