Recently, I had to maintain a system that is developed in Visual Basic. Net, and the truth is that this crazy, you see, my problem is this, I have a GridView:
<asp:GridView ID="GvwTrack" runat="server" AutoGenerateColumns="False" CellPadding="4"
EmptyDataText="[No se ha registrado un Track]" ForeColor="#333333" GridLines="None"
TabIndex="65" Width="100%" DataKeyNames="LoteTrackId,TipoTrackId">
<Columns>
<asp:CommandField SelectText="Borrar" ShowSelectButton="True" />
<asp:BoundField DataField="LoteTrackId" HeaderText="ID" Visible="False" />
<asp:BoundField DataField="Tracking" HeaderText="TRACK">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Sitio" HeaderText="SITIO">
</asp:BoundField>
<asp:BoundField DataField="Mensajero" HeaderText="MENSAJERO">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="Responsable" HeaderText="RESPONSABLE">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="Fecha" HeaderText="FECHA" DataFormatString="{0:d}">
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="Hora" DataFormatString="{0:t}" HeaderText="HORA">
<ItemStyle Width="80px" />
</asp:BoundField>
</Columns>
</asp:GridView>
In the codeBeside the gridView is filled through a Sub and up to here everything is fine, the information shows correctly in the table
Sub CargarListaTracking()
Dim ListaTracking As New DataTable
Dim ConsultarTracking As New SqlCommand("SELECT [LoteTrackId], [TipoTrackId], [Sitio], [Responsable], [Mensajero], [Fecha], [Hora], " _
& " (CASE WHEN TipoTrackId = '1' THEN 'Recolección' " _
& " WHEN TipoTrackId = '2' THEN 'Devolución' " _
& " WHEN TipoTrackId = '3' THEN 'Enlace de Mensajería' " _
& " WHEN TipoTrackId = '4' THEN 'Entrega Parcial' " _
& " WHEN TipoTrackId = '5' THEN 'Entrega Final' END) AS Tracking " _
& " FROM [OperacionesTracking] " _
& " WHERE ([IdGuia] = @IdGuia) " _
& " ORDER BY [Fecha], [Hora]")
ConsultarTracking.Parameters.AddWithValue("@IdGuia", HdnIdGuia.Value)
ConsultarTracking.Connection = C.Conecta_Albatros
C.Data_Adapter = New SqlDataAdapter(ConsultarTracking)
C.Data_Adapter.Fill(ListaTracking)
GvwTrack.DataSource = ListaTracking
GvwTrack.DataBind()
End Sub
You have a Sub SelectedIndexChanged in which you need to obtain a DataKey data pair from the GridView: LoteTrackId and TipoTrackId
Protected Sub GvwTrack_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GvwTrack.SelectedIndexChanged
Dim LoteTrackId As Integer = Convert.ToInt32(GvwTrack.DataKeys(GvwTrack.SelectedIndex).Value(0))
Dim TipoTrackId As Byte = Convert.ToByte(GvwTrack.DataKeys(GvwTrack.SelectedIndex).Value(1))
.... Mas codigo
End Sub
When executing it, it throws me an error, in which it marks line 168, which is where I try to recover the LoteTrackId and it says the following:
Error de servidor en la aplicación '/'.
No se encontró ningún miembro predeterminado para el tipo 'Integer'.
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.
Detalles de la excepción: System.MissingMemberException: No se encontró ningún miembro predeterminado para el tipo 'Integer'.
Error de código fuente:
Línea 166:
Línea 167: Protected Sub GvwTrack_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GvwTrack.SelectedIndexChanged
Línea 168: Dim LoteTrackId As Integer = Convert.ToInt32(GvwTrack.DataKeys(GvwTrack.SelectedIndex).Value(0))
Línea 169: Dim TipoTrackId As Byte = Convert.ToByte(GvwTrack.DataKeys(GvwTrack.SelectedIndex).Value(1))
Línea 170:
I have been trying to solve this all day and I do not understand what is wrong, I have consulted several forums and pages, it is assumed that the DataKeys query is correct, I hope you can help me, in advance, thanks.