[英]Taking Distinct Column along with other column values also from DataTable in C#
[英]Distinct Values From DataTable c#
我已經將xml
轉換為DataTable
。 我有一個datatable
類似這樣的。 它描述了一家特定酒店的房間選擇。 如果板類型,房間類型,房間價格相同,我想將其分為兩個房間。
Room 1
Boards Type Room Type Room Price Sleep Up To
Room Only Double Standard 301.280 2 Guests
Room Only Double Standard 301.280 2 Guests
我想像這樣。
Room 1
Boards Type Room Type Room Price Sleep Up To
Room Only Double Standard 301.280 2 Guests
Room 2
Boards Type Room Type Room Price Sleep Up To
Room Only Double Standard 301.280 2 Guests
以下是我嘗試使用的代碼,沒有客人使用。 之后,我發現僅不使用任何客人就無法打破這一點。 所以我想用3列打破它,並想打印為2號房間。
PlaceHolder1.Controls.Add(new LiteralControl("<div class='type1 pd10-lr pd15-tb'>"));
var noofroom = (from row2 in dt2.AsEnumerable()
where (Int64)row2["hotelcode"] == hotelcode
select row2.Field<string>("guests")).Distinct();
int a = 1;
foreach (var rcount in noofroom)
{
PlaceHolder1.Controls.Add(new LiteralControl("<div class='rhead'>" +
"Room " + a + "" +
"</div>" +
"<table class='roomtbl'>" +
"<tr>" +
"<td class='tdaltbg'>" +
"<strong> " +
"Board Type</strong></td>" +
"<td class='style30'>" +
"<strong> " +
"Room Type</strong></td>" +
"<td class='tdaltbg'>" +
"<strong> Room Price</strong></td>" +
"<td class='style30'>" +
"<strong> " +
"Sleep Up To</strong></td>" +
"<td class='tdaltbg'>" +
"<strong></strong></td>" +
"</tr>"));
DataRow[] drs = dt2.Select("hotelcode='" + hotelcode + "' AND guests='" + rcount + "'");
foreach (DataRow dr in drs)
{
PlaceHolder1.Controls.Add(new LiteralControl("<tr>" +
"<td class='tdaltbg'>" +
" " +
"" + dr["board"] + "</td>" +
"<td class='style30'>" +
"" + dr["roomtype"] + "</td>" +
"<td class='tdaltbg'>" +
" " +
"£ " + dr["amount"] + "</span></td>" +
"<td class='style30'>" +
" " +
" " + dr["guests"] + " Guests</span></td>" +
"<td class='tdaltbg'>"));
PlaceHolder1.Controls.Add(new LiteralControl("<input type='radio' name='t1' data-price='308.560' checked='checked'/>" +
"</td>" +
"</tr>"));
}
PlaceHolder1.Controls.Add(new LiteralControl("</table>"));
a++;
}
請嘗試這個。 在這里,可以將多個列作為參數傳遞,對於true則傳遞true。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.