Get values row selected ListView

0

I want to get the information of a selected row of ListView to pass them to an object with the same (and other more) fields. I tried with SelectedItemTemplate (since SelectedItems does not appear to me) but I can not index it (or index it?) Because it does not leave me.

I need to do something like this:

obj.codigo = LitView.SelectedItem[0].toString();
obj.nombre = LitView.SelectedItem[1].toString();

Where [0] would be the code of the selected element, [1] the name of the same, ect.

If it works, here is the ListView code:

'

   <GroupTemplate>
        <tr runat="server">
            <td id="itemPlaceholder" runat="server"></td>
        </tr>
    </GroupTemplate>

    <LayoutTemplate>
        <table>
            <td runat="server" id="groupPlaceholder"></td>
        </table>
    </LayoutTemplate>


    <ItemTemplate>

        <td class="align text-center">
            <br />
            <asp:Label ID="codArt" runat="server" Text='<%# Eval("CodArticulo_A") %>' Visible="false" />
            <asp:ImageButton ID="ImageButton1" ImageUrl='<%# Eval("Imagen_A") %>' runat="server" CommandName="eventoImageButton1" OnCommand="ImageButton1_Command" />
            <br />
            <asp:Label ID="nombreLibro" runat="server" Text='<%# Eval("Nombre_A") %>' />
            <br />
            <asp:Label ID="nombreAutor" runat="server" Text='<%# Eval("NombreAutor") %>' />
            <br />
            $  
                <asp:Label ID="Precio" runat="server" Text='<%# Eval("PrecioUnitario_A") %>' />
            <br />
            <asp:Button ID="addCarrito" runat="server" CssClass="btn" CommandArgument='<%# Eval("Nombre_A") %>' Text="Agregar al carrito" OnCommand="addCarrito_Command"    />

        </td>

    </ItemTemplate>
</asp:ListView>'
    
asked by Yamila Marucci 15.03.2017 в 17:05
source

1 answer

1

When your ListView is in Detail mode the selected item is only shown in the first column, the rest of the columns you have to access them as SubItems

listView1.SelectedItems[0].SubItems[0].Text;
listView1.SelectedItems[0].SubItems[1].Text;
listView1.SelectedItems[0].SubItems[2].Text;
    
answered by 15.03.2017 в 18:26