473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 5924

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jon Ripley | last post by:
Using VB6 (for two weeks!) I could get a ListBox search working perfectly but with a ListView it has completely stumped me. I've not found any previous posts that have helped :( The user...
2
by: David Anderson | last post by:
I'm working on a Windows app that has a ListView containing a bunch of items. When the user clicks on an item, the app displays the item'd details. The user then has the opportunity to edit these...
9
by: Devron Blatchford | last post by:
Hi there, Just wondering if I change the back and fore colour of a listview item when the mouse hovers over it? I want to overide the default windows colour. Can someone please tell me how to...
1
by: Shane | last post by:
I have a text box select items in a listview as text is being typed into the text box. I get the select bar to move correctly in the Listview control. If the user presses the down or up key in...
4
by: Shane | last post by:
I have a text box select items in a listview as text is being typed into the text box. I get the select bar to move correctly in the Listview control. If the user presses the down or up key in...
4
by: Lars Netzel | last post by:
I have a long list of Items in a ListView... if I scroll down to something that is not visible without scrolling and then click on it I open another window where you can work with the details of...
2
by: Mike | last post by:
Ok I'm having a problem with a listview. I have a listview on a WinForm called ProgramInformationFrm. I call this from from 2 other forms. One is ProgramSearch Frm, the other is OpenNCFrm. The...
6
by: Brandon McCombs | last post by:
Hello, I have a form that contains a listview on the left side and a column of buttons on the right side. Only some of the buttons do I want enabled all the time. The other buttons should be...
4
by: Bill-R | last post by:
I'm trying to convert a vb6 program to vb.net (vb2008 express) I have text data in a Listview Control I use a Textbox to enter characters to search the Listview When a Match is found, I use...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.