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 SelectedIndexCh anging
event. Not sure if this is related to the color problem, but is that what you
are supposed to do?
<asp:ListView ID="lvSearchRes ults" DataKeyNames="M emberID"
OnDataBound="lv SearchResults_D ataBound"
OnSelectedIndex Changing="lvSea rchResults_Sele ctedIndexChangi ng"
OnSelectedIndex Changed="lvSear chResults_Selec tedIndexChanged " 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="MemberIDLab el" runat="server" Text='<%# Eval("MemberID" )
%>' />
<br />
<h5 style="display: inline;">
Name:
</h5>
<asp:Label ID="FullnameLab el" runat="server" Text='<%# Eval("FullName" )
%>' />
<br />
<h5 style="display: inline;">
State/Postal Code:
</h5>
<asp:Label ID="StateCodeLa bel" runat="server" Text='<%# Eval("State") %>'
/>
/
<asp:Label ID="PostalCodeL abel" runat="server" Text='<%#
Eval("PostalCod e") %>' />
<br />
<h5 style="display: inline;">
Home Phone:
</h5>
<asp:Label ID="HomePhoneNu mberLabel" runat="server" Text='<%#
Eval("PhoneNumb er") %>' />
<br />
<asp:CheckBox ID="ActionFlagC heckBox" runat="server" Checked='<%#
Eval("ActionFla g") %>'
Enabled="false" Style="font-weight: bold;" Text="Action Flag" />
<asp:ImageButto n ID="btnSelect" Style="position : absolute; bottom: 2px;
right: 2px;" CommandName="Se lect" ImageUrl="~/Images/Buttons/s_select_0.png"
tooltip="Submit this search criteria" runat="server" />
</div>
</ItemTemplate>
<AlternatingIte mTemplate>
<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="MemberIDLab el" runat="server" Text='<%# Eval("MemberID" )
%>' />
<br />
<h5 style="display: inline;">
Name:
</h5>
<asp:Label ID="FullnameLab el" runat="server" Text='<%# Eval("Fullname" )
%>' />
<br />
<h5 style="display: inline;">
State/Postal Code:
</h5>
<asp:Label ID="StateCodeLa bel" runat="server" Text='<%# Eval("State") %>'
/>
/
<asp:Label ID="PostalCodeL abel" runat="server" Text='<%#
Eval("PostalCod e") %>' />
<br />
<h5 style="display: inline;">
Home Phone:
</h5>
<asp:Label ID="HomePhoneNu mberLabel" runat="server" Text='<%#
Eval("PhoneNumb er") %>' />
<br />
<asp:CheckBox ID="ActionFlagC heckBox" runat="server" Checked='<%#
Eval("ActionFla g") %>'
Enabled="false" Style="font-weight: bold;" Text="Action Flag" />
<asp:ImageButto n ID="btnSelect" Style="position : absolute; bottom: 2px;
right: 2px;" CommandName="Se lect" ImageUrl="~/Images/Buttons/s_select_0.png"
tooltip="Submit this search criteria" runat="server" />
</div>
</AlternatingItem Template>
<LayoutTemplate >
<div id="itemPlaceho lder" style="text-align: center; background-color:
#CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
color: #000000;" runat="server">
</div>
</LayoutTemplate>
<SelectedItemTe mplate>
<div id="Div3" style="text-align: left; border: solid 1px gray;
background-color: #FFFF99; color: #333333;" runat="server">
Member ID:
<asp:Label ID="MemberIDLab el" runat="server" Text='<%# Eval("MemberID" )
%>' />
<br />
Name:
<asp:Label ID="FullnameLab el" runat="server" Text='<%# Eval("Fullname" )
%>' />
<br />
State/Postal Code:
<asp:Label ID="StateCodeLa bel" runat="server" Text='<%# Eval("State") %>'
/>
/
<asp:Label ID="PostalCodeL abel" runat="server" Text='<%#
Eval("PostalCod e") %>' />
<br />
Home Phone:
<asp:Label ID="HomePhoneNu mberLabel" runat="server" Text='<%#
Eval("PhoneNumb er") %>' />
<br />
<asp:CheckBox ID="ActionFlagC heckBox" runat="server" Checked='<%#
Eval("ActionFla g") %>'
Enabled="false" Text="Action Flag" />
<br />
</div>
</SelectedItemTem plate>
<ItemSeparatorT emplate>
<br />
</ItemSeparatorTe mplate>
</asp:ListView>
protected void lvSearchResults _SelectedIndexC hanging(object sender,
ListViewSelectE ventArgs e)
{
lvSearchResults .SelectedIndex = e.NewSelectedIn dex;
}
<asp:ObjectData Source ID="odsQuickDet ails" runat="server"
OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etQuickDetails" TypeName="App_C lasses.Members" >
<SelectParamete rs>
<asp:ControlPar ameter ControlID="lvSe archResults" Name="MemberID"
PropertyName="S electedValue" Type="String" />
</SelectParameter s>
</asp:ObjectDataS ource>