开发者

ListView selected index

I have a paged multicolumn ListView of items with ImageButton and LinkButton. The delete and select commands are working. I can't get the SelectedIndexChanging event to fire, and the SelectedIndex is always -1 in the Select command handler. I think I have the required select button as per the docs. My ultimate goal is to save the index of the item so when I return to the page I can restore the current ListView pager page so the selected item is visible. But I can't get the item index. This is for asp.net 4.0 webforms.

<asp:ListView ID="ListView1" runat="server" OnItemDataBound="ListView1_ItemDataBound"
  DataKeyNames="ItemID" DataSourceID="ObjectDataSource1"
  OnItemCommand="ListView1_ItemCommand" GroupItemCount="2" 
  onselectedindexchanging="ListView1_SelectedIndexChanging">
  <LayoutTemplate>
    <table width="100%">
      <tr>
        <td>
          <table class="sample" width="100%">
            <asp:PlaceHolder runat="server" ID="groupPlaceHolder"></asp:PlaceHolder>
          </table>
        </td>
      </tr>
    </table>
  </LayoutTemplate>
  <GroupTemplate>
    <tr>
      <asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>
    </tr>
  </GroupTemplate>
  <ItemTemplate>
    <td>
      <asp:ImageB开发者_运维知识库utton ID="btnDelete" ToolTip="Delete" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>' CommandName="DeleteItem" Height="12" ImageUrl="resources/delete.gif" Width="12" />
      <asp:LinkButton ID="btnSelect" runat="server" CommandName="Select" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>'><%# DataBinder.Eval(Container.DataItem, "ItemName") %></asp:LinkButton>
      <asp:Label ID="ccLabel" runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;
    </td>
  </ItemTemplate>
</asp:ListView>


It would help if you posted your code (SelectedIndexChanging). But in any case, one thought:

SelectedIndexChanging won't give you the selected index, because the index hasn't actually been selected yet.

Use SelectedIndexChanged instead. This occurs after the index has been selected, so can give you a value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜