0

I have converted xml to DataTable . I Have a datatable similar like this. It's describe the room options in one specific hotel. I want to break this into two room if boards type, room type, room price are same.

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    

I want to make it similar like this.

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  

Below Is My Code Which I have tried break this using no of guests. after did that I found It's not right way to break this only using no of guests. so I want to break this using 3 columns and want to print as room 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>&nbsp;" +
                             "Board Type</strong></td>" +
                             "<td class='style30'>" +
                                 "<strong>&nbsp;" +
                             "Room Type</strong></td>" +
                             "<td class='tdaltbg'>" +
                                 "<strong>&nbsp;&nbsp; Room Price</strong></td>" +
                                 "<td class='style30'>" +
                                 "<strong>&nbsp;" +
                             "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'>" +
                                     "&nbsp;" +
                                     "" + dr["board"] + "</td>" +
                                "<td class='style30'>" +
                                     "" + dr["roomtype"] + "</td>" +
                                 "<td class='tdaltbg'>" +
                                     "&nbsp;" +
                                     "£ " + dr["amount"] + "</span></td>" +
                                       "<td class='style30'>" +
                                     "&nbsp;" +
                                     " " + 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++;

                }
zkanoca
  • 9,664
  • 9
  • 50
  • 94
Sirojan Gnanaretnam
  • 601
  • 1
  • 22
  • 45
  • I'd suggest to take a look @ [this SO post](http://stackoverflow.com/questions/1199176/how-to-select-distinct-values-from-datatable/1199956#1199956) – Mechanical Object Jul 29 '13 at 06:09

1 Answers1

0

Please try this. Here multiple columns can be passed as parameter and true for distinct.

Muhammad Saad
  • 186
  • 1
  • 13