开发者

How would I parse a filename from a location I grab from a table before it's bound to the dropdownlist?

So in one of my tables, there lies an image file location. I'm grabbing that information to be displayed in an asp:dropdownlist, however, I want just the name of the image to be displayed. How/Where would I parse the filename out of it. Also, is there a built in method for grabbing the filename?

EDIT::

http://msdn.microsoft.com/en-us/library/bb397663.aspx

instead of:

var oData = from c in oDb.CustomerImages
                    where c.CustomerID == CustomerID         &&
                          c.CustomerNumber == CustomerNumber &&
                          c.Catego开发者_StackOverflow中文版ryID == CategoryID
                    orderby c.ID
                    select new { Path.GetFileName(c.Location), c.ID };

just set it to a variable, and then set you set your dropdownlist.DataTextField = to that variable's name:

solution:

var oData = from c in oDb.CustomerImages
                    where c.CustomerID == CustomerID         &&
                          c.CustomerNumber == CustomerNumber &&
                          c.CategoryID == CategoryID
                    orderby c.ID
                    select new { Location = Path.GetFileName(c.Location), c.ID };

        return oData;

//elsewhere  ...

dropdownlist.DataTextField = "Location";


You should be able to use

Path.GetFileName

Returns the file name and extension of the specified path string.


There's a Path class that has lots of useful methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜