469,568 Members | 1,720 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

ListView Selected Item Not Working

I have a listview that when I select an item, it populates a details view. I
want to show the item that was selected in the listview by changing it to
yellow. Trouble is, the selected item does not show as yellow until I've
clicked the same item two times. What am I doing wrong on the selected item
that keeps it from changing to yellow until the item is clicked two times?
Also, I have to set the listviews selectedIndex in the SelectedIndexChanging
event. Not sure if this is related to the color problem, but is that what you
are supposed to do?

<asp:ListView ID="lvSearchResults" DataKeyNames="MemberID"
OnDataBound="lvSearchResults_DataBound"
OnSelectedIndexChanging="lvSearchResults_SelectedI ndexChanging"
OnSelectedIndexChanged="lvSearchResults_SelectedIn dexChanged" runat="server">
<ItemTemplate>
<div id="Div1" style="text-align: left; border: solid 1px gray;
background-color: #F7F6F3; color: #333333; position: relative;"
runat="server">
<h5 style="display: inline;">
Member ID:
</h5>
<asp:Label ID="MemberIDLabel" runat="server" Text='<%# Eval("MemberID")
%>' />
<br />
<h5 style="display: inline;">
Name:
</h5>
<asp:Label ID="FullnameLabel" runat="server" Text='<%# Eval("FullName")
%>' />
<br />
<h5 style="display: inline;">
State/Postal Code:
</h5>
<asp:Label ID="StateCodeLabel" runat="server" Text='<%# Eval("State") %>'
/>
/
<asp:Label ID="PostalCodeLabel" runat="server" Text='<%#
Eval("PostalCode") %>' />
<br />
<h5 style="display: inline;">
Home Phone:
</h5>
<asp:Label ID="HomePhoneNumberLabel" runat="server" Text='<%#
Eval("PhoneNumber") %>' />
<br />
<asp:CheckBox ID="ActionFlagCheckBox" runat="server" Checked='<%#
Eval("ActionFlag") %>'
Enabled="false" Style="font-weight: bold;" Text="Action Flag" />
<asp:ImageButton ID="btnSelect" Style="position: absolute; bottom: 2px;
right: 2px;" CommandName="Select" ImageUrl="~/Images/Buttons/s_select_0.png"
tooltip="Submit this search criteria" runat="server" />
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div id="Div2" style="text-align: left; border: solid 1px gray;
background-color: #FFFFFF; color: #333333; position: relative;"
runat="server">
<h5 style="display: inline;">
Member ID:
</h5>
<asp:Label ID="MemberIDLabel" runat="server" Text='<%# Eval("MemberID")
%>' />
<br />
<h5 style="display: inline;">
Name:
</h5>
<asp:Label ID="FullnameLabel" runat="server" Text='<%# Eval("Fullname")
%>' />
<br />
<h5 style="display: inline;">
State/Postal Code:
</h5>
<asp:Label ID="StateCodeLabel" runat="server" Text='<%# Eval("State") %>'
/>
/
<asp:Label ID="PostalCodeLabel" runat="server" Text='<%#
Eval("PostalCode") %>' />
<br />
<h5 style="display: inline;">
Home Phone:
</h5>
<asp:Label ID="HomePhoneNumberLabel" runat="server" Text='<%#
Eval("PhoneNumber") %>' />
<br />
<asp:CheckBox ID="ActionFlagCheckBox" runat="server" Checked='<%#
Eval("ActionFlag") %>'
Enabled="false" Style="font-weight: bold;" Text="Action Flag" />
<asp:ImageButton ID="btnSelect" Style="position: absolute; bottom: 2px;
right: 2px;" CommandName="Select" ImageUrl="~/Images/Buttons/s_select_0.png"
tooltip="Submit this search criteria" runat="server" />
</div>
</AlternatingItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholder" style="text-align: center; background-color:
#CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
color: #000000;" runat="server">
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<div id="Div3" style="text-align: left; border: solid 1px gray;
background-color: #FFFF99; color: #333333;" runat="server">
Member ID:
<asp:Label ID="MemberIDLabel" runat="server" Text='<%# Eval("MemberID")
%>' />
<br />
Name:
<asp:Label ID="FullnameLabel" runat="server" Text='<%# Eval("Fullname")
%>' />
<br />
State/Postal Code:
<asp:Label ID="StateCodeLabel" runat="server" Text='<%# Eval("State") %>'
/>
/
<asp:Label ID="PostalCodeLabel" runat="server" Text='<%#
Eval("PostalCode") %>' />
<br />
Home Phone:
<asp:Label ID="HomePhoneNumberLabel" runat="server" Text='<%#
Eval("PhoneNumber") %>' />
<br />
<asp:CheckBox ID="ActionFlagCheckBox" runat="server" Checked='<%#
Eval("ActionFlag") %>'
Enabled="false" Text="Action Flag" />
<br />
</div>
</SelectedItemTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
</asp:ListView>
protected void lvSearchResults_SelectedIndexChanging(object sender,
ListViewSelectEventArgs e)
{
lvSearchResults.SelectedIndex = e.NewSelectedIndex;
}

<asp:ObjectDataSource ID="odsQuickDetails" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetQuickDetails" TypeName="App_Classes.Members">
<SelectParameters>
<asp:ControlParameter ControlID="lvSearchResults" Name="MemberID"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>

Aug 12 '08 #1
0 5561

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jon Ripley | last post: by
2 posts views Thread by David Anderson | last post: by
9 posts views Thread by Devron Blatchford | last post: by
1 post views Thread by Shane | last post: by
2 posts views Thread by Mike | last post: by
6 posts views Thread by Brandon McCombs | last post: by
4 posts views Thread by Bill-R | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.