0

这可能看起来很微不足道,我曾经一次知道如何做到这一点,但由于某种原因,这次我似乎无法理解它:

我有两张桌子:桌子上有Hotel和其他酒店详细信息,并且在不同HotelRooms 的房间类型中找到,每个房间类型都有描述。一间酒店可以有多种房型。HotelHotelIDHotelIDHotelRooms

我有一个DropDownList包含HotelIDRoomIDs. HotelID来自会话变量。HotelID是 RoomType Roomtypes GridView` 的值,DropDownList; but the list displays包含. When酒店are selected I want to display a房间详细信息,如描述、价格等......

我不能这样做,因为我的 DropDownList 的值HotelID是映射到Session ID. 请问如何从 DropDownList 的选定值中获取 HotelRoom 详细信息?

更新:

网格视图的代码:

        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>
4

3 回答 3

2

尝试SelectedItem.Text下拉列表。

于 2012-05-25T00:00:55.587 回答
2

'DropDownList1.SelectedValue' 应该为您提供@intResortID.
'DropDownList2.SelectedValue' 应该为您提供@strRoomType.

DropDownList2_SelectedIndexChanged应该通过填充一些东西(比如DataTable)来运行查询。
填充的 DataTable 应该绑定到您的 GridView。

在您的DropDownList2_SelectedIndexChanged方法中尝试以下操作:

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);
DataTable results = new DataTable();

sdr.Fill(results);

resultsGridView.DataSource = results;   //Assuming resultsGridView is the name of the GridView on your ASPX page.
resultsGridView.DataBind();
于 2012-05-25T00:58:07.100 回答
0

听起来您需要在 HotelRooms 表中唯一标识每个房间的新 ID(主键)。如果你有这个,你可以用它作为下拉列表的值,问题就消失了。

于 2012-05-25T00:06:22.520 回答