Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically displaying a menu

Status
Not open for further replies.

belle9

Programmer
Nov 3, 2004
87
US
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>
 
A related question:

When I try to call a javascript function from within my linkbutton, I get:
'javascript' is not a member of 'ASP.products_aspx'.

How do I call a js function from within .net?

<asp:datalist id="dlCategories" Runat="server">
<ItemTemplate>
<p class="wht_14" style="margin:8px 14px 8px 0px"><b>
<asp:LinkButton ID="lnkButton" OnClick="javascript:show('A')" Runat="server" CommandArgument='<%# Container.DataItem("categoryID") %>'>
<%#Databinder.Eval(Container.Dataitem, "CategoryName")%>
</asp:LinkButton>
</b>
</p>
</ItemTemplate>
</asp:datalist>
 
Thanks for the response.

Please clarify what you mean by: add the key/value to the control's attribute collection.

Thanks!
 
tgreer means that you should use the Add method of the Attributes prpoerty for that control. e.g.
Code:
lnkButton.Attributes.Add

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top