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!

Executing show/hide javascript with a nested datalist 1

Status
Not open for further replies.

belle9

Programmer
Nov 3, 2004
87
US
I'm trying to do a simple show/hide: when you click on a category, it's corresponding products appear below it. Click the category again, and the menu folds back up.

What's happening now is that when I click on an item in dlCategories, it's corresponding dlProduct appears for a second, but then I guess it goes back to the server which causes the products to disappear again...(didn't make sense did it?)

Any ideas???

I don't think I need to show my javascript here: I'm pretty sure it works, as I've used it outside of .Net countless of times. If you want to see it, I'll post it.

I've added the javascript call like this, which works to a degree:
Code:
 objButton.Attributes.Add("onclick", "javascript: show('products');")



Here are my nested datalists: (not sure why it doesnt display nicely formatted..sorry)
Code:
<!-- Begin Category Listing -->
									<asp:datalist id="dlCategories" runat="server">
										<ItemTemplate>
											<P class="wht_11" style="MARGIN: 0px 18px 8px 0px"><b>
													<asp:LinkButton id="Linkbutton1" Runat="server" CommandArgument='<%# Container.DataItem("categoryID") %>' CommandName="Edit">
														<%#Container.DataItem("CategoryName")%>
													</asp:LinkButton></b></P>
											<!-- Begin Product Listing -->
											<td id="products" style="display: none'" runat=server>
												<asp:DataList ID="dlProd" Runat="server">
													<ItemTemplate>
														<P class="wht_11" style="MARGIN: 0px 18px 8px 0px">
															<asp:LinkButton id="linkButton2" Runat="server" OnClick="ProductDetailClicked" CommandArgument='<%# Container.DataItem("productsID") %>'>
																<%#Container.DataItem("ProductName")%>
															</asp:LinkButton></P>
													</ItemTemplate>
												</asp:DataList>
											</td>
											<!-- End Product Listing -->
										</ItemTemplate>
									</asp:datalist>
									<!-- End Category Listing -->

Thanks for any tips!
 
dlProd is reliant on clicking LinkButton1 (which posts back to the server) in dlCategories, right? Why don't you just stick dlProd in a Panel control and toggle it's visibility?
 
Veep, sounds promising. I'll check out the Panel control, haven't seen or used it before.

How will I toggle its visibility though? Is there some way for me to tell the server when to toggle? How will distinguish between 1 click and two..?
 
Veep:

Panel1.Visible = !Panel1.Visible;

I put that in the javascript function, right?
 
Never mind, I got it, works great, 99%! One small thing though: I have to click on dlcategories twice to get dlprod to display. What do I have wrong?
 
Got it, sorry! I set the visible to false on the panel itself...

Thanks tons Veep.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top