?
Solved

DataList SelectedItem

Posted on 2006-06-28
6
Medium Priority
?
1,391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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