开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜