Link to home
Start Free TrialLog in
Avatar of fizch
fizch

asked on

DataList SelectedItem

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>
Avatar of Edward Diaz
Edward Diaz
Flag of United States of America image

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
Avatar of fizch
fizch

ASKER

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.
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
ASKER CERTIFIED SOLUTION
Avatar of Edward Diaz
Edward Diaz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial