M
Mike Collins
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_SelectedIndexChanging"
OnSelectedIndexChanged="lvSearchResults_SelectedIndexChanged" 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>
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_SelectedIndexChanging"
OnSelectedIndexChanged="lvSearchResults_SelectedIndexChanged" 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>