rygar2006
asked on
Assign selectedindex of datalist with datakey value
I have a nagivation bar created with a datalist. Each item of the datalist has a link with a querystring value with the name pageID which is the same value as the datakey for that item.
I'm trying to select an item in a datalist by comparing the datalist items datakey value with the pageID value from the querystring.
<asp:datalist id="dlstNav" runat="server" DataKeyField="pageID">
<ItemTemplate>
<LI>
<A href='index.aspx?pageID=<% # container.dataitem("pageID ")%>'>
<%# container.dataItem("pageti tle")%>
</A>
</LI>
</ItemTemplate>
</asp:datalist>
'Receives that querystring value
Dim pageID As Integer
pageID = Request.QueryString("catID ")
If Not catID = Nothing Then
Dim item As DataListItem
For Each item In dlstNav.Items
If item.(get value of datakey) = pageID Then
dlstNav.selectedindex = item.itemindex
end if
Next
end if
I'm trying to select an item in a datalist by comparing the datalist items datakey value with the pageID value from the querystring.
<asp:datalist id="dlstNav" runat="server" DataKeyField="pageID">
<ItemTemplate>
<LI>
<A href='index.aspx?pageID=<%
<%# container.dataItem("pageti
</A>
</LI>
</ItemTemplate>
</asp:datalist>
'Receives that querystring value
Dim pageID As Integer
pageID = Request.QueryString("catID
If Not catID = Nothing Then
Dim item As DataListItem
For Each item In dlstNav.Items
If item.(get value of datakey) = pageID Then
dlstNav.selectedindex = item.itemindex
end if
Next
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Private Sub dlstNav_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles dlstNav.Load
Dim catID As Integer
catID = Request.QueryString("catID
Dim lblcatID As Label
For Each li As DataListItem In dlstNav.Items
lblcatID = li.FindControl("lblcatID")
If lblcatID.Text = catID Then
dlstNav.SelectedIndex = li.ItemIndex
End If
Next
End Sub