How To Get/Set SelectedItem in a Nested ListView?
I'm using a nested ListView to display a list of LinkButtons. I want to get the SelectedIndex (the clicked linkbutton) in the ListView but it is always -1. Below is my code.
<asp:ListView ID="lvw" runat="server" EnableViewState="true"
OnItemCommand="ItemCommand" OnSelectedIndexChanging="lvw_OnSelectedIndexChanging" OnDataBound="lvw_OnDataBound">
<LayoutTemplate>
<ul style="margin-left: 0px; padding-left: 25px; list-style-type:none; color:Black;">
<li id="itemPlaceholder" runat="server" style="margin-left: 0px;"/>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li style="margin-bottom: 10px; margin-left: 0px;">
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="NoUnderline"
ForeColor="Black" OnCommand="QueueLinkButton_Click" OnDataBinding="QueueLinkButton_DataBind"
CommandName='<%# Eval("SubQueueId")%>'
CommandArgument='<%# Eval("QueueName")%>'><%# Eval("QueueName")%>
</asp:LinkButton>
<asp:ListView runat="server" ID="lvw2"
DataSource='<%# Eval("ChildQueueNodes")%>'>
<LayoutTemplate>
<ul style="margin-top: 10px; margin-left: 0px;
padding-left: 25px; list-style-type:none; color:Black;">
<li id="itemPlaceholder" runat="server" style="margin-left: 0px;"/>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li style="margin-bottom: 10px; margin-left: 0px;">
<asp:LinkButton ID="LinkButton2" runat="server" CssCl开发者_JAVA百科ass="NoUnderline"
ForeColor="Black" OnCommand="QueueLinkButton_Click" OnDataBinding="QueueLinkButton_DataBind"
CommandName='<%# Eval("SubQueueId")%>'
CommandArgument='<%# Eval("QueueName")%>'><%# Eval("QueueName")%>
</asp:LinkButton>
</li>
</ItemTemplate>
</asp:ListView>
</li>
</ItemTemplate>
</asp:ListView>
精彩评论