Datagrid nested in Datalist (passing parameters)
Hi
I have a datalist which shows a list of hotel rooms available in a hotel. There is a "Click for Prices" link button, which when clicked, displays the <SelectedItemTemplate> of the datalist. Inside this, is a datagrid, where I want to display all the prices for the hotel room selected. The problem I'm having is that I'm unsure how to pass through the selected "roomID" to the function which populates the prices datagrid.
From some of the reading I have done, I found that I needed to use as OnItemDataBound in my datalist to then be able to reference the dataGrid (because it only appears when the SelectedItemTemplate displays). I have used OnItemDataBound="BindGrid" to reference the DataGrid, and then want to try and pass a CommandArgument through as a parameter to my getprices function.
Here is all the relevant code (which might help explain what i'm going on about):
*************************************************
Sub Page_Load(Sender As Object, E As EventArgs)
If Not IsPostBack Then
dlistRooms.DataSource = getRooms()
dlistRooms.DataBind()
End Sub
Sub DataList_ItemCommand(Sender As Object, E As DatalistCommandEventArgs)
Dim cmd As String = E.CommandSource.CommandName
If cmd = "select" Then
dlistRooms.SelectedIndex = 0
End If
dlistRooms.DataSource = getRooms(E.CommandSource.CommandArgument)
dlistRooms.DataBind()
End Sub
Sub BindGrid(Sender As Object, E As DataListItemEventArgs)
Dim listType As ListItemType = CType(E.Item.ItemType ListItemType)
If listType = ListItemType.SelectedItem Then
Dim dGrid As DataGrid = CType(E.Item.FindControl("dgridPrices"), DataGrid)
dGrid.DataSource = getPrices("SHE01")
dgGrid.DataBind()
End If
End Sub
Function getRooms() As DataSet
... code that gets the hotel room types from the database ...
End Function
Function getRooms(ByVal room_ID As String) As DataSet
... overloaded function for getting a SELECTED room type...
End Function
Function getPrices(ByVal room_ID As String) As DataSet
... code in here which gets the prices for a SELECTED room type...
End Function
And then my datalist/datagrid...
<asp:DataList id="dlistRooms" runat="server" onItemCommand="DataList_ItemCommand" onItemDataBound="BindGrid">
<ItemTemplate>
<h4><%# DataBinder.Eval(Container.DataItem, "room_Name") %></h4>
<h4>No. Bedrooms: <%# DataBinder.Eval(Container.DataItem, "room_Bedrooms") %></h4>
<h4>No. Sharing: <%# DataBinder.Eval(Container.DataItem, "room_Sharing") %></h4>
<h4><asp:LinkButton id="btnPrice" runat="server" CommandName="select" CommandArgument='<%# Container.DataItem("room_ID") %>' Text="Click for prices" /></h4>
</ItemTemplate>
<SelectedItemTemplate>
<h4><%# DataBinder.Eval(Container.DataItem, "room_Name") %></h4>
<h4>No. Bedrooms: <%# DataBinder.Eval(Container.DataItem, "room_Bedrooms") %></h4>
<h4>No. Sharing: <%# DataBinder.Eval(Container.DataItem, "room_Sharing") %></h4>
<asp:DataGrid id="dgridPrices" runat="server" />
</SelectedItemTemplate>
</asp:DataList>
</ItemTemplate>
|