Can I trim strings when I manage them to a DropDownList by DataSource?
I have this code :
myObjects ps = new myObjects();
myDD.DataSource = ps;
myDD.DataTextField = "Title";
myDD.DataValueField = "ItemID";
myDD.DataBind();
that a开发者_如何学Godd a Text/Value pair values to a DropDownList.
I'd like to add these valus trimming it (so remove empty space first and in the end).
Is it possible on #C/.NET?
myDD.DataSource = ps.Cast<YourItemType>().Select(i => new {
Title = i.Title.Trim(),
ItemID = i.ItemID.Trim()});
myDD.DataTextField = "Title";
myDD.DataValueField = "ItemID";
myDD.DataBind();
if ps is a DataTable, you should be able to do
myDD.DataSource = ps.Cast<DataRow>().Select(i => new {
Title = i["Title"].Trim(),
ItemID = i["ItemID"].Trim()});
myDD.DataTextField = "Title";
myDD.DataValueField = "ItemID";
myDD.DataBind();
精彩评论