Solved

DataList SelectedItem

Posted on 2006-06-28
6
1,377 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…

730 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