<%@ Page language="VB" %>
<!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)
Dim row As GridViewRow = CustomersGridView.SelectedRow
MessageLabel.Text = "Has seleccionado a " & row.Cells(1).Text & "."
Dim cadena As String = row.Cells(1).Text
Label2.Text = "Has seleccionado a " & cadena & "."
End Sub
Sub CustomersGridView_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
Dim row As GridViewRow = CustomersGridView.Rows(e.NewSelectedIndex)
If row.Cells(1).Text = "ANATR" Then
e.Cancel = True
MessageLabel.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>GridView Select Example</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">
<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>
<selectedrowstyle backcolor="LightCyan"
forecolor="DarkBlue"
font-bold="true"/>
</asp:gridview>
<br/>
<asp:label id="MessageLabel"
forecolor="Red"
runat="server"/>
<asp:label id="Label2"
forecolor="Red"
runat="server"/>
<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=myID;Password=mypass;Trusted_Connection=no"
runat="server"/>
<asp:gridview id="Gridview1"
datasourceid="Sqldatasource1"
autogeneratecolumns="False"
autogenerateselectbutton="True"
allowpaging="True"
selectedindex="1"
onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
onselectedindexchanging="CustomersGridView_SelectedIndexChanging"
runat="server" DataKeyNames="rpe">
<Columns>
<asp:BoundField DataField="rpe"
HeaderText="RPE del Empleado"
InsertVisible="False" ReadOnly="True"
SortExpression="b_contra.fe_repro" />
<asp:BoundField DataField="fe_inic"
HeaderText="Nombre del Empleado"
SortExpression="c_zonas.nombre" />
<asp:BoundField DataField="cl_incid"
HeaderText="Edad del Empleado"
SortExpression="fe_inic" />
</Columns>
<selectedrowstyle backcolor="LightCyan"
forecolor="DarkBlue"
font-bold="true"/>
</asp:gridview>
<br/>
<asp:sqldatasource id="Sqldatasource1"
selectcommand="SELECT rpe, fe_inic, cl_incid FROM b_asiste WHERE cl_incid='026' AND rpe='"&cadena&"' GROUP BY rpe, cl_incid, fe_inic"
connectionstring="server=myhost;database=mydb;User ID=myID;Password=mypass;Trusted_Connection=no"
runat="server"/>
</form>
</body>
</html>