473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

DataList Selecteditem template

Hello!

I am building a navigation menu using DataList and templates. I have spent
hours trying to find a solution to my problem, but without any luck. Maybe
someone knows how to solve this problem...?

Here is what I need to achieve...

If ItemType is Item, print: "Item Name >"
If ItemType is SelectedItem, print: "Item Name <"
Thank you in advance!
Scott
Below is my code...

<asp:DataList id="dlMenuItems" runat="server" Width="180" BorderWidth="0"
DataKeyField="ID">
<SelectedItemTemplate>
<asp:HyperLink id="hlSelectedMenuItem" Runat="Server"></asp:HyperLink>
</SelectedItemTemplate>
<ItemTemplate>
<asp:HyperLink id="hlMenuItem" Runat="Server"></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlMenuItems.ItemDataBound

Dim hlSelectedMenuItem As HyperLink
Dim hlMenuItem As HyperLink

hlSelectedMenuItem = CType(e.Item.FindControl("hlSelectedMenuItem"),
HyperLink)
hlMenuItem = CType(e.Item.FindControl("hlMenuItem"), HyperLink)

Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

If Not drv Is Nothing Then
hlMenuItem.Text = drv("CategoryNameEst") & ">"
hlMenuItem.NavigateUrl = "../Browse.aspx?CatId=" & drv("ID")
End If

End If

If e.Item.ItemType = ListItemType.SelectedItem Then

If Not drv Is Nothing Then
hlSelectedMenuItem.Text = drv("CategoryNameEst") & "<"
hlSelectedMenuItem.NavigateUrl = "../Browse.aspx?tId=" &
drv("ID")
End If

End If

End Sub
Nov 18 '05 #1
1 4070
Got it working... I just had to set DataList SelectedIndex before DataBind
:-)

Scott

Hello!

I am building a navigation menu using DataList and templates. I have spent
hours trying to find a solution to my problem, but without any luck. Maybe
someone knows how to solve this problem...?

Here is what I need to achieve...

If ItemType is Item, print: "Item Name >"
If ItemType is SelectedItem, print: "Item Name <"
Thank you in advance!
Scott
Below is my code...

<asp:DataList id="dlMenuItems" runat="server" Width="180" BorderWidth="0"
DataKeyField="ID">
<SelectedItemTemplate>
<asp:HyperLink id="hlSelectedMenuItem" Runat="Server"></asp:HyperLink>
</SelectedItemTemplate>
<ItemTemplate>
<asp:HyperLink id="hlMenuItem" Runat="Server"></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlMenuItems.ItemDataBound

Dim hlSelectedMenuItem As HyperLink
Dim hlMenuItem As HyperLink

hlSelectedMenuItem = CType(e.Item.FindControl("hlSelectedMenuItem"),
HyperLink)
hlMenuItem = CType(e.Item.FindControl("hlMenuItem"), HyperLink)

Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

If Not drv Is Nothing Then
hlMenuItem.Text = drv("CategoryNameEst") & ">"
hlMenuItem.NavigateUrl = "../Browse.aspx?CatId=" & drv("ID")
End If

End If

If e.Item.ItemType = ListItemType.SelectedItem Then

If Not drv Is Nothing Then
hlSelectedMenuItem.Text = drv("CategoryNameEst") & "<"
hlSelectedMenuItem.NavigateUrl = "../Browse.aspx?tId=" &
drv("ID")
End If

End If

End Sub

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Barry | last post by:
I have a three-level drilldown report. The top level is a DataList. When an item is selected, a new DataList is instantiated in the SelectedItem template. I'd like to have the same thing happen...
2
by: Leo Duran | last post by:
Hi, I am working on an app right now that makes extensive use of the DataList control. I chose the DataList because I need to do multi row formatting. I am using it like so.
8
by: MattB | last post by:
I think I'm close to making this work, but so far it does not. I have a datalist (id = "dlVFields") on a web form that has an item template with a textbox in it. The textbox id = "txtVerify"....
3
by: sling blade | last post by:
Hi, I have a dropdownlist in my DataList control and I am trying to set the SelectedItem property of the dropdownlist so when the datalist displays the user will see the text in the dropdownlist...
3
by: Michael Groeger | last post by:
Hi, I have a DataList which is filled with a custom control. The custom control contains a image and a label. The problem is that neither the SelectedIndexChanged event of the DataList is fired...
0
by: Scott Reynolds | last post by:
Hello! I am building a navigation menu using DataList and templates. I have spent hours trying to find a solution to my problem, but without any luck. Maybe someone knows how to solve this...
0
by: Isz | last post by:
PROBLEM: This problem is related to the postback and handling events correctly. BACKGROUND: I have a datalist which acts as a tabbes list with horizontal layout. This datalist is bound to a...
0
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have a simple datalist on my web page that's attached to a sqldatasource that i specified on the quick task menu for the datalist. The datalist contains a linkbutton (command name =...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.