This may seem very trivial, I used to know how to do this at one time but for some reason I can’t seem to get my head around it this time:
I have two tables: Hotel and HotelRooms
The Hotel table has HotelID and other hotel details and the HotelID is found in HotelRooms with different roomtypes, each roomtype has a description.
One Hotel can have many rooms types.
I have a DropDownList that contains HotelID and RoomIDs. HotelID comes from a session variable. HotelID is the value for the DropDownList; but the list displaysRoomType.Roomtypes
Whenare selected I want to display aGridView` with the hotel room details like description, price etc….
I can’t do this because the value for my DropDownList is HotelID which is mapped to the Session ID. How do I get the HotelRoom details from the selected value of the DropDownList, please?
Update:
Code for Gridview:
string intResortID = Request.QueryString("intResortID ")
string strRoomType = DropDownList2.SelectedValue;
string connStr = ConfigurationManager.ConnectionStrings["bdsConnectionString"].ConnectionString;
SqlConnection Con = new SqlConnection(connStr);
SqlDataAdapter sdr = new SqlDataAdapter("SELECT TOP (100) PERCENT tblAvail.dtm, tblResortsRooms.strRoomType, tblResortsRooms.strDescription, tblAvail.intQty, tblAvail.curPrice, tblAvail.intResortID, tblResortsRooms.intWSCode FROM tblAvailable INNER JOIN tblResortsRooms ON tblAvail.intResortID = tblResortsRooms.intResortID AND tblAvail.strRoomType = tblResortsRooms.strRoomType WHERE (tblResortsRooms.curRecRate > 0) AND (tblAvail.intResortID = @intResortID) AND (tblAvail.strRoomType = @strRoomType) AND (tblAvailable.dtm >= { fn CURDATE() }) ORDER BY tblResortsRooms.strRoomType",Con);
SqlParameter ResID = new SqlParameter("@intResortID", intResortID);
SqlParameter RoomType = new SqlParameter("@strRoomType", strRoomType);
sdr.SelectCommand.Parameters.Add(ResID);
sdr.SelectCommand.Parameters.Add(RoomType);
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource2" DataTextField="strRoomType"
DataValueField="intResortID"
onselectedindexchanged="DropDownList2_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
SelectCommand="SELECT [intResortID], [strRoomType] FROM [tblResortsRooms] WHERE ([intResortID] = @intResortID)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="intResortID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
‘DropDownList1.SelectedValue’ should give you the value for
@intResortID.‘DropDownList2.SelectedValue’ should give you the value for
@strRoomType.DropDownList2_SelectedIndexChangedshould run the query by filling something (like a DataTable).The filled DataTable should be bound to your GridView.
Try something like the following in your
DropDownList2_SelectedIndexChangedmethod: