I'm pretty much a beginner with asp.net. What I would like to achieve is: I have a left navigation with categories, and I'd like for when the user clicks on a category title for its corresponding products to display beneath it. When they click on the title again, the products should disappear.
I retrieve both the categories and products from a sql database, and right now they're displaying as datalists.
So what I'm trying to do is get the dlProducts into some kind of javascript function to display as a submenu only when the user clicks on an item in the dlCategories, then to fold/close up again when they click on another category.
Here's what I have:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BindDataList(lblMsg, dlCategories, conString, "getCategories")
End Sub
Private Sub dlProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlProducts.ItemCommand
myConnection = New SqlConnection(conString)
myConnection.Open()
mycommand = New SqlCommand("getSpecificProduct", myConnection)
mycommand.CommandType = CommandType.StoredProcedure
Dim objButton As LinkButton
objButton = CType(e.CommandSource, LinkButton)
mycommand.Parameters.Add(New SqlParameter("@productsID", SqlDbType.Int))
mycommand.Parameters("@productsID").Value = objButton.CommandArgument
myReader = mycommand.ExecuteReader
Me.Bind_Data(myReader)
myConnection.Close()
End Sub
<tr>
<td background="/images/tile_diamondmenu2.gif" align="right" style="BORDER-BOTTOM:#abc1dd 1px solid">
<asp:datalist id="dlCategories" Runat="server">
<ItemTemplate>
<p class="wht_14" style="margin:8px 14px 8px 0px"><b>
<asp:LinkButton ID="lnkButton" Runat="server" CommandArgument='<%# Container.DataItem("categoryID") %>'>
<%#Databinder.Eval(Container.Dataitem, "CategoryName")%>
</asp:LinkButton>
</b>
</p>
</ItemTemplate>
</asp:datalist>
<!--start sub categories -->
<table>
<tr>
<td>
<asp:datalist id="dlProducts" runat="server">
<ItemTemplate>
<P class="wht_11" style="MARGIN: 0px 18px 8px 0px">
<asp:LinkButton id=Linkbutton3 Runat="server" CommandArgument='<%# Container.DataItem("productsID") %>'>
<%#Container.DataItem("ProductName")%>
</asp:LinkButton></P>
</ItemTemplate>
</asp:datalist>
</td>
</tr>
</table>
<asp:label id="lblMsg" runat="server" Visible="False"></asp:label>
<!--end sub categories -->
</td>
</tr>
I retrieve both the categories and products from a sql database, and right now they're displaying as datalists.
So what I'm trying to do is get the dlProducts into some kind of javascript function to display as a submenu only when the user clicks on an item in the dlCategories, then to fold/close up again when they click on another category.
Here's what I have:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BindDataList(lblMsg, dlCategories, conString, "getCategories")
End Sub
Private Sub dlProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlProducts.ItemCommand
myConnection = New SqlConnection(conString)
myConnection.Open()
mycommand = New SqlCommand("getSpecificProduct", myConnection)
mycommand.CommandType = CommandType.StoredProcedure
Dim objButton As LinkButton
objButton = CType(e.CommandSource, LinkButton)
mycommand.Parameters.Add(New SqlParameter("@productsID", SqlDbType.Int))
mycommand.Parameters("@productsID").Value = objButton.CommandArgument
myReader = mycommand.ExecuteReader
Me.Bind_Data(myReader)
myConnection.Close()
End Sub
<tr>
<td background="/images/tile_diamondmenu2.gif" align="right" style="BORDER-BOTTOM:#abc1dd 1px solid">
<asp:datalist id="dlCategories" Runat="server">
<ItemTemplate>
<p class="wht_14" style="margin:8px 14px 8px 0px"><b>
<asp:LinkButton ID="lnkButton" Runat="server" CommandArgument='<%# Container.DataItem("categoryID") %>'>
<%#Databinder.Eval(Container.Dataitem, "CategoryName")%>
</asp:LinkButton>
</b>
</p>
</ItemTemplate>
</asp:datalist>
<!--start sub categories -->
<table>
<tr>
<td>
<asp:datalist id="dlProducts" runat="server">
<ItemTemplate>
<P class="wht_11" style="MARGIN: 0px 18px 8px 0px">
<asp:LinkButton id=Linkbutton3 Runat="server" CommandArgument='<%# Container.DataItem("productsID") %>'>
<%#Container.DataItem("ProductName")%>
</asp:LinkButton></P>
</ItemTemplate>
</asp:datalist>
</td>
</tr>
</table>
<asp:label id="lblMsg" runat="server" Visible="False"></asp:label>
<!--end sub categories -->
</td>
</tr>