<%@ Page language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub CustomersGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
' Get the currently selected row using the SelectedRow property.
Dim row As GridViewRow = CustomersGridView.SelectedRow
' Display the company name from the selected row.
' In this example, the third column (index 2) contains
' the company name.
Dim cadena As String = row.Cells(1).Text
Dim MyConnection As SqlConnection = New SqlConnection("connectionstring="server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no")
Dim MyCommand As SqlCommand = New SqlCommand("SELECT rpe as RPE_del_Empleado, convert(varchar,fe_inic,103) as Fecha_de_la_Incidencia, cl_incid AS Tipo_de_Incidencia FROM b_asiste WHERE cl_incid='026' AND rpe='" & cadena & "' GROUP BY rpe, cl_incid, fe_inic", MyConnection)
MyConnection.Open()
Dim dr As SqlDataReader = MyCommand.ExecuteReader()
MyDataGrid.DataSource = dr
MyDataGrid.DataBind()
If cadena = "" Then
Label1.Text = "Has seleccionado a " & cadena & ""
Else
Label2.Text = "Has seleccionado a " & cadena & ". No existen incidencias para este empleado"
End If
End Sub
Sub CustomersGridView_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
' Get the currently selected row. Because the SelectedIndexChanging event
' occurs before the select operation in the GridView control, the
' SelectedRow property cannot be used. Instead, use the Rows collection
' and the NewSelectedIndex property of the e argument passed to this
' event handler.
Dim row As GridViewRow = CustomersGridView.Rows(e.NewSelectedIndex)
' You can cancel the select operation by using the Cancel
' property. For this example, if the user selects a customer with
' the ID "ANATR", the select operation is canceled and an error message
' is displayed.
If row.Cells(1).Text = "ANATR" Then
e.Cancel = True
Label2.Text = "You cannot select " + row.Cells(1).Text & "."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>GridView Select Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Trabajadores jubilables mayores de 55 años con más de 25 años trabajando</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="False"
autogenerateselectbutton="True"
allowpaging="True"
selectedindex="1"
onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
onselectedindexchanging="CustomersGridView_SelectedIndexChanging"
runat="server" DataKeyNames="rpe" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
GridLines="None">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:BoundField DataField="rpe"
HeaderText="RPE del Empleado"
InsertVisible="False" ReadOnly="True"
SortExpression="b_contra.fe_repro" />
<asp:BoundField DataField="nombre"
HeaderText="Nombre del Empleado"
SortExpression="c_zonas.nombre" />
<asp:BoundField DataField="Edad"
HeaderText="Edad del Empleado"
SortExpression="fe_inic" />
<asp:BoundField DataField="nombrezona"
HeaderText="Nombre de la Zona"
SortExpression="fe_inic" />
<asp:BoundField DataField="area"
HeaderText="Area en que labora"
SortExpression="fe_inic" />
<asp:BoundField DataField="puesto"
HeaderText="Puesto"
SortExpression="fe_inic" />
<asp:BoundField DataField="fe_natra"
HeaderText="Fecha de Nacimiento"
SortExpression="fe_inic" />
<asp:BoundField DataField="fe_antre"
HeaderText="Fecha de Antigüedad Reconocida"
SortExpression="fe_inic" />
<asp:BoundField DataField="fe_ingre"
HeaderText="Fecha de Ingreso"
SortExpression="fe_inic" />
<asp:BoundField DataField="ubicacion"
HeaderText="Ubicación"
SortExpression="fe_inic" />
<asp:BoundField DataField="nides"
HeaderText="nides"
SortExpression="fe_inic" />
<asp:BoundField DataField="nire"
HeaderText="nire"
SortExpression="fe_inic" />
<asp:BoundField DataField="fe"
HeaderText="Fecha Probable de Jubilación"
SortExpression="fe_inic" />
<asp:BoundField DataField="anyjub"
HeaderText="Años Transcurridos Desde la jubilación"
SortExpression="fe_inic" />
<asp:BoundField DataField="fepos"
HeaderText="Fecha Probable Para Jubilación"
SortExpression="fe_inic" />
</Columns>
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<selectedrowstyle backcolor="DarkSlateBlue"
forecolor="GhostWhite"/>
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:gridview>
<br/>
<asp:label id="Label1"
forecolor="Red"
runat="server"/>
<asp:label id="Label2"
forecolor="Red"
runat="server"/>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="SELECT MAX(b_contra.fe_repro), MAX(c_zonas.nombre) AS nombrezona, MAX(c_puesto.puesto) AS puesto, MAX(c_a_resp.dscarea) AS area, b_traba1.rpe, MAX(b_traba1.nombre) AS nombre, b_traba1.fe_antre, b_traba1.fe_ingre, b_traba3.fe_natra, CONVERT (INT,(DATEDIFF (dd, b_traba3.fe_natra, GETDATE()) - DATEDIFF (yy, b_traba3.fe_natra, GETDATE()) / 4.25) / 365) AS Edad, MAX(b_traba1.sexotrab) AS sexo, MAX(c_ubica.ubicapza) AS ubicacion, MAX(b_traba1.cl_nides) AS nides, MAX(b_traba1.if_nire2) AS nire, fe, CASE WHEN fe<GETDATE() THEN GETDATE() ELSE null END AS fepos, CONVERT (INT,(DATEDIFF (dd, GETDATE(), fe) - DATEDIFF (yy, GETDATE(), fe) / 4.25) / 365) AS anyjub FROM (SELECT fe_antre, CASE WHEN b_traba1.sexotrab='M' THEN DATEADD(yy, 30, b_traba1.fe_antre) ELSE DATEADD(yy, 25, b_traba1.fe_antre) END AS fe FROM b_traba1) AS t1, b_traba1, b_traba3, c_zonas, c_a_resp, c_ubica, c_puesto, b_contra WHERE (DATEDIFF(yy, b_traba1.fe_antre, GETDATE()) > 25) AND (DATEDIFF(yy, b_traba3.fe_natra, GETDATE()) > 55) AND b_traba1.cl_sitla IS NULL AND c_zonas.descr=b_traba1.cl_zona AND c_a_resp.area=b_traba1.area AND b_traba1.rpe=b_traba3.rpe AND b_traba1.rpe=b_contra.rpe AND c_puesto.cl_puest=b_contra.cl_puest AND b_traba1.fe_antre=t1.fe_antre AND b_traba1.cl_ubica=c_ubica.cl_ubica GROUP BY b_traba1.rpe, b_traba1.fe_antre, b_traba1.fe_ingre, b_traba3.fe_natra, fe"
connectionstring="server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no"
runat="server"/>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700px"
BackColor="LightGoldenrodYellow"
BorderColor="Tan"
CellPadding=2
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="False" BorderWidth="1px" Font-Names="Verdana"
ForeColor="Black" GridLines="None"
>
<AlternatingItemStyle BackColor="PaleGoldenrod" />
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
</asp:DataGrid>
</form>
</body>
</html>