Binding a custom Object to a drop down

Posted by Nandakumarpb under ASP.NET category on | Views : 2169
I have a roomtype table which have 3 column hotelId,RoomTypeId and description. In My BL class (Room) I defined a structure for the room type

struct RoomType

public int HotelId { get; set; }
public int RoomTypeId { get; set; }
public string RoomDesc { get; set; }

In My Page where I need to show the Room Type (This page is checking the availability of Rooms in selected hotel). I am using the following code

Session["HotelId"] = 121; //Selected hotel Id
Rooms ObjRooms = new Rooms(); //BL Class have some Methods related to Room
DataTable dtRType = new DataTable();
string strSQL = "Select roomTypeId,RoomDescription from RoomType where hotelid=" + int.Parse(Session["HotelId"].ToString());
dtRType = ObjRooms.GetRoomType(strSQL);
RoomType ObjRT = new RoomType();
List<RoomType> ObjGenRoomType = new List<RoomType>();
foreach (DataRow dr in dtRType.Rows)
ObjRT.RoomTypeId = short.Parse(dr[0].ToString());
ObjRT.RoomDesc = dr[1].ToString();
ddlRoomType.DataSource = ObjGenRoomType;
ddlRoomType.DataTextField = "RoomDesc";
ddlRoomType.DataValueField = "roomTypeId";

Comments or Responses

Login to post response