开发者

How can I add a line break in my LINQ query?

开发者 https://www.devze.com 2023-02-28 03:49 出处:网络
I need to add a line break in my LINQ query in the \"select new\" section. I tried <br /> and \"\\n\" but those didn\'t seem to work. Any clue which command to use to get the line break?

I need to add a line break in my LINQ query in the "select new" section. I tried <br /> and "\n" but those didn't seem to work. Any clue which command to use to get the line break?

I want to display airline image underneath the airline symbol using linq. Should I store the image path in the xml file and then query using linq? Here's the code I've g开发者_开发问答ot so far:

var query = from f in XElement.Load(MapPath("flightdata2.xml")).Elements("flight") select new {

Airline = (string)f.Element("airline"), DepartureAirportSymbol = (string)f.Element("departureAirportSymbol"), DepartTime = (string)f.Element("departureTime"), DestinationAirportSymbol = (string)f.Element("destinationAirportSymbol"), ArrivalTime = (string)f.Element("arrivalTime"), Stops = (int)f.Element("numberOfStops"), Duration = (string)f.Element("duration"), Cabin = (string)f.Element("class"), Price = "$" + (Int32)f.Element("price") };


Try

 Environment.NewLine  

For most cases it's the same as \r\n, but it's better in case it ever got run on a system that didn't use \r\n.


System.Environment.NewLine is useful for inserting line breaks in strings in a typical setting. However, if you're trying to produce a line break in a web page, then you need to use "<br />" for an HTML line break.


If I were to guess, I'd say you probably want to flatten the results of a query for display using String.Join(@"<br />", results); If so, I would explore using a bound control instead.

But then we can only guess having absolutely no information to go on...

What, exactly, is happening now. What code are you using? What would you like to see happen?

Edit: Pulling this up from comments in response to your clarification:

I would use a template field in your gridview, or use a repeater instead of a gridview. This is a presentation concern, not a data concern. Don't worry about trying to do it in LINQ.

Either a template field or a repeater will allow you to place two "fields" on top of each other on the same row for display purposes:

http://www.asp.net/data-access/tutorials/using-templatefields-in-the-gridview-control-cs

0

精彩评论

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

关注公众号