Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ListView Selected Item Not Working

Reply
Thread Tools

ListView Selected Item Not Working

 
 
Mike Collins
Guest
Posts: n/a
 
      08-12-2008
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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help to fill textboxes from a selected item in datagrid-selected index changed. mldardy ASP .Net 0 09-28-2010 02:59 PM
asp.net ListView control - Configure ListView option missing? . ASP .Net 0 07-24-2010 12:20 AM
ListView selected index WebBuilder451 ASP .Net 2 04-25-2008 10:04 PM
ListView and LinqDataSource. Delete item shapper ASP .Net 1 02-19-2008 05:27 PM
DropDownList 2 always returns Selected = 0 for all items - even selected item Iain ASP .Net 3 12-11-2006 11:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57