Ich möchte meine Liste in einer HTML-Tabelle anzeigen oder so, dass ich die Ausgabe formatieren kann.C# Liste in einer formatierten Tabelle anzeigen
Unten ist mein Code und ein Link zu einem Bild, das zeigt, was ich erreichen möchte. Jede Bestellnummer sollte eine eigene Tabelle haben.
Ich verwendete ursprünglich einen Repeater, aber weil ich Artikel mit der gleichen ID gruppieren muss, konnte ich nicht richtig angezeigt werden.
Danke.
public class myProducts
{
public int Order { get; set; }
public string Date { get; set; }
public string Qty { get; set; }
public string GrandTotal { get; set; }
public string Ship_FirstName { get; set; }
public string Ship_LastName { get; set; }
public string Item { get; set; }
public string Options { get; set; }
}
List<myProducts> products = new List<myProducts>();
myProducts product = new myProducts
{
Order = 1111,
Date = "5/8/2017",
Qty = "2",
GrandTotal = "$50.00",
Ship_FirstName = "John",
Ship_LastName = "Doe",
Item = "Item 4",
Options = "Option1, Option2, Option3, Option4",
};
products.Add(product);
product = new myProducts
{
Order = 1111,
Date = "5/8/2017",
Qty = "2",
GrandTotal = "$50.00",
Ship_FirstName = "John",
Ship_LastName = "Doe",
Item = "Item 4",
Options = "Option1, Option2, Option3, Option4",
};
products.Add(product);
product = new myProducts
{
Order = 34556,
Date = "5/9/2017",
Qty = "2",
GrandTotal = "$200.00",
Ship_FirstName = "John",
Ship_LastName = "Doe",
Item = "Item 4",
Options = "Option1, Option2, Option3, Option4",
};
products.Add(product);
product = new myProducts
{
Order = 143566,
Date = "5/2/2017",
Qty = "2",
GrandTotal = "$100.00",
Ship_FirstName = "John",
Ship_LastName = "Doe",
Item = "Item 4",
Options = "Option1, Option2, Option3, Option4",
};
products.Add(product);
var groups = products.GroupBy(x => new { x.Order, x.GrandTotal, x.Date, x.Ship_FirstName, x.Ship_LastName });
foreach (var group in groups)
{
var line1 = "Order # " + group.Key.Order + " <br />" + "Order Placed: " + group.Key.Date + " <br />" + " Total: " + group.Key.GrandTotal + " <br />" + " Ship To: " + group.Key.Ship_FirstName + " " + group.Key.Ship_LastName;
Line1.Text = Line1.Text + " <br /> " + line1.ToString() ;
foreach (var item in group)
{
var line2 = " -- Item: " +item.Item + " <br /> " + "-- Options: " + item.Options;
Line1.Text = Line1.Text + " <br /> " + line2.ToString();
}
}
Platform? Winform/ASP-Webformular/MVC? –
@MAdeelKhalid Sorry, ASP.net Webformular –