Solved

DataList SelectedItem

Posted on 2006-06-28
6
1,370 Views
Last Modified: 2009-10-15
I've got a problem with a DataList that I am using in a user control for a kind of navigation system. My problem is that the selected item style is applied to the item, but it still uses the item template to load the controls. I am using .Net 1.1 and listed below is the html for the user control.

<div align=left style="width: 100%; background-color: #E5D797;">
      <asp:datalist id="SubMenu" CssClass="SubMenu" RepeatDirection="Horizontal" runat="server">
            <SelectedItemTemplate>
                  <%# CType(Container.DataItem, TabItem).Name %>
            </SelectedItemTemplate>
            <SelectedItemStyle CssClass="SubSelectedItem"></SelectedItemStyle>
            <ItemStyle CssClass=SubItem></ItemStyle>
            <ItemTemplate>
                  <a class=NavigationLink href="<%# CType(Container.DataItem, TabItem).Path %>"><%# CType(Container.DataItem, TabItem).Name %></a>
            </ItemTemplate>
      </asp:datalist>
</div>
0
Comment
Question by:fizch
  • 3
6 Comments
 
LVL 4

Expert Comment

by:Kittrick
ID: 17005697
Hi there,
I found an example at:

http://webmatrixproject.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/ctrlref/data/DataList/DataList2.src

Where it shows the <SelectedItemTemplate>, and it's after the <ItemTemplate>, whereas in your code yours is before.  I've found about 3 other MS sites that showed the same thing.


<asp:DataList id="whatever" runat="server" >
              <HeaderTemplate>
                Items
              </HeaderTemplate>
              <ItemTemplate>
               
             </ItemTemplate>
              <SelectedItemTemplate>
               
              </SelectedItemTemplate>

        </asp:DataList>

Hopefully this solves your problem!
Kittrick
0
 
LVL 6

Author Comment

by:fizch
ID: 17009112
That is actually where it started out. I tried moving them around to see if that was the cause of the problem, but alas there was no improvement.
0
 
LVL 4

Expert Comment

by:Kittrick
ID: 17012678
It never ceases to amaze me about how many ways there are to solve the same problem. Here's how I solved the a similar problem except I was needing the different CSS layout in the <EditItemTemplate>. The concepts should be the same even though the actual code is different.

<head>
<style type="text/css">
.hr {color: black;font-size: 9px}
td.happyborder {border: 5px dashed black; background-color:light-gray}
</style>
</head>

<asp:DataList runat="server" Id="datalist1" Font-Size="5pt">
<ItemTemplate>

<%# DataBinder.Eval(Container.DataItem,"yourfield")%>

</itemtemplate>

<EditItemTemplate>

<table>
<tr>
<td class="happyborder" valign=top style="background-color: #CCCCCC">
<asp:textbox id="yourfield_" runat="server"  cssclass="hr" text='<%# DataBinder.Eval(Container.DataItem, "yourfield")%>'/>

</td>
</tr>
</table>

</EditItemTemplate>
</asp:datalist>



I hope this helps!
Kittrick
0
 
LVL 4

Accepted Solution

by:
Kittrick earned 500 total points
ID: 17012753
Alternatively, you might want to try:

<asp:DataList id="whatever" runat="server" >

<!----this code was missing from your orig. code or out of order--->
<SelectedItemStyle BackColor="Yellow">
         </SelectedItemStyle>
<!----this code was missing from your orig. code or out of order--->


              <HeaderTemplate>
                Items
              </HeaderTemplate>
              <ItemTemplate>
               
             </ItemTemplate>

              <SelectedItemTemplate>
               
              </SelectedItemTemplate>

        </asp:DataList>



I found this in the example at:
http://msdn.microsoft.com/library/?url=/library/en-us/cpref/html/frlrfSystemWebUIWebControlsDataListClassSelectedItemTemplateTopic.asp

Kittrick


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now