• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1399
  • Last Modified:

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>
0
fizch
Asked:
fizch
  • 3
1 Solution
 
KittrickCommented:
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
 
fizchAuthor Commented:
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
 
KittrickCommented:
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
 
KittrickCommented:
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

Technology Partners: 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!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now