Posted By

systemergon on 02/11/16


Tagged

GridView SeletedIndexChanging SeletedIndex


Versions (?)

Obtener opción seleccionada de GridView


 / Published in: VB.NET
 

Como podemos obtener la selección del GridView, debemos declarar DataKeyName

  1. VISTA DISEÑO
  2.  
  3. <asp:GridView runat="server" ID="GvVentas" DataKeyNames="ID" OnRowUpdating="GvVentas_RowUpdating"
  4. OnSelectedIndexChanging ="GvVentas_SelectedIndexChanging" OnRowEditing ="GvVentas_RowEditing" AutoGenerateColumns="False" OnRowCancelingEdit="GvVentas_RowCancelingEdit">
  5.  
  6. <Columns>
  7. <asp:CommandField HeaderText="Edit-Update" ShowEditButton="True" />
  8. <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" />
  9. <asp:BoundField DataField="TIE" HeaderText="TIE" ReadOnly="true"/>
  10. <asp:BoundField DataField="CREDITO" HeaderText="CREDITO" ReadOnly="true" />
  11. <asp:BoundField DataField="CONTADO" HeaderText="CONTADO" ReadOnly="true" />
  12. <asp:BoundField DataField="TOTAL" HeaderText="TOTAL" ReadOnly="true" />
  13.  
  14. <asp:TemplateField HeaderText="FCH" SortExpression="FCH">
  15. <ItemTemplate>
  16. <asp:Label ID="LBFch" runat="server" Text='<%# Bind("FCH") %>'></asp:Label>
  17. </ItemTemplate>
  18. <EditItemTemplate>
  19. <asp:TextBox ID="TXTFch" runat="server" Text='<%# Bind("FCH") %>'></asp:TextBox>
  20. </EditItemTemplate>
  21. </asp:TemplateField>
  22.  
  23.  
  24.  
  25. </Columns>
  26. <RowStyle BackColor="#E3EAEB" />
  27. </asp:GridView>
  28.  
  29.  
  30. -------- CODIGO SERVIDOR -------
  31.  
  32. 'Opcion Seleccionada
  33. Protected Sub GvVentas_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GvVentas.SelectedIndexChanging
  34. Dim editID As Integer
  35. editID = Convert.ToInt32(GvVentas.DataKeys(e.NewSelectedIndex).Value)
  36. End Sub

Report this snippet  

You need to login to post a comment.