ITsolutionWizard
asked on
linq data sorted
Below codes is to return .net datatable, and I use asp.net repeater to bind it. everything is working except the list does not sort by date and time. The data source starts from query3.
Not sure why. and hope some experts can help out.
Thanks
var query3 = query1.Concat(query2).Orde rBy(z => z.DateTimeSent);
Not sure why. and hope some experts can help out.
Thanks
var query3 = query1.Concat(query2).Orde
public static DataTable GetConversation(string sid, string token,string accountPhoneNo, string twilioPhoneNo)
{
string clientPhoneNo = string.Empty;
string inputFilePath = filePathUserMessagesAll;
DataTable dt = new DataTable();
dt.Clear();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("Body",typeof(string)),
new DataColumn("DateCreated",typeof(string)),
new DataColumn("Direction",typeof(string)),
new DataColumn("SelectedPhoneNo",typeof(string))
});
XDocument xdoc = null;
using (XmlReader xr = XmlReader.Create(inputFilePath))
{
xdoc = XDocument.Load(xr);
var query1 = from t in xdoc.Descendants("User")
where
(
t.Element("From").Value.ToLower() == "+1" + accountPhoneNo.ToLower()
) //client phone
select new
{
Body = t.Element("Body").Value,
DateTimeSent = t.Element("DateTimeSent").Value,
Direction = t.Element("Direction").Value,
To = t.Element("To").Value
};
var query2 = from t in xdoc.Descendants("User")
where t.Element("To").Value.ToLower() == "+1" + accountPhoneNo.ToLower()
select new
{
Body = t.Element("Body").Value,
DateTimeSent = t.Element("DateTimeSent").Value,
Direction = t.Element("Direction").Value,
To = t.Element("From").Value
};
var query3 = query1.Concat(query2).OrderBy(z => z.DateTimeSent);
foreach (var x in query3)
{
dt.Rows.Add(x.Body,(DateTime.Parse(x.DateTimeSent)).ToString("MM/dd/yy h:mm", System.Globalization.CultureInfo.InvariantCulture),x.Direction,accountPhoneNo);
}System.Globalization.CultureInfo.InvariantCulture);
xr.Close();
return dt;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did that work out for you?
Solution posted.