开发者

Can I trim strings when I manage them to a DropDownList by DataSource?

开发者 https://www.devze.com 2023-04-05 08:00 出处:网络
I have this code : myObjects ps = new myObjects(); myDD.DataSource = ps; myDD.DataTextField = \"Title\";

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

精彩评论

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

关注公众号