如何在嵌套ListView中获取/设置SelectedItem?

时间:2011-08-08 08:03:17

标签: asp.net listview selectedindex

我正在使用嵌套的ListView来显示LinkBut​​tons的列表。我想在ListView中获取SelectedIndex(单击的链接按钮),但它始终为-1。以下是我的代码。

<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" CssClass="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>

0 个答案:

没有答案