Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/11/2011, 09:52
Avatar de stuart_david3
stuart_david3
 
Fecha de Ingreso: agosto-2011
Mensajes: 215
Antigüedad: 12 años, 8 meses
Puntos: 1
Pregunta Abrir nueva págna con un DataGrid

Hola!!! Tengo un problema no se como generar una nueva ventana en base a un Gridview. Por ejemplo: Al darle clic a un campo HyperLink en mi GridView me genera un DataGrid con las insidencias del empleado que elegí con el HyperLink (ese empleado lo guardo en la variable "cadena" con el SelectedRow de mi GrridView). Eso hasta el momento gracias a Dios lo tengo, ahora quisiera saber cómo hacerle para que el DataGrid que genero me lo haga en una ventana nueva... Aquí les dejo el código...

Código ASP:
Ver original
  1. <%@ Page language="VB" %>
  2. <%@ Import Namespace="System.Data" %>
  3. <%@ Import Namespace="System.Data.SqlClient" %>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  5.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6.  
  7. <script runat="server">
  8.  
  9.   Sub CustomersGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
  10.  
  11.     ' Get the currently selected row using the SelectedRow property.
  12.     Dim row As GridViewRow = CustomersGridView.SelectedRow
  13.  
  14.     ' Display the company name from the selected row.
  15.     ' In this example, the third column (index 2) contains
  16.         ' the company name.
  17.         Dim cadena As String = row.Cells(1).Text
  18.         Dim MyConnection As SqlConnection = New SqlConnection("connectionstring="server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no")
  19.         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)
  20.  
  21.         MyConnection.Open()
  22.  
  23.         Dim dr As SqlDataReader = MyCommand.ExecuteReader()
  24.         MyDataGrid.DataSource = dr
  25.         MyDataGrid.DataBind()
  26.        
  27.         If cadena = "" Then
  28.             Label1.Text = "Has seleccionado a " & cadena & ""
  29.         Else
  30.             Label2.Text = "Has seleccionado a " & cadena & ". No existen incidencias para este empleado"
  31.         End If
  32.        
  33.     End Sub
  34.  
  35.     Sub CustomersGridView_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
  36.  
  37.         ' Get the currently selected row. Because the SelectedIndexChanging event
  38.         ' occurs before the select operation in the GridView control, the
  39.         ' SelectedRow property cannot be used. Instead, use the Rows collection
  40.         ' and the NewSelectedIndex property of the e argument passed to this
  41.         ' event handler.
  42.         Dim row As GridViewRow = CustomersGridView.Rows(e.NewSelectedIndex)
  43.  
  44.         ' You can cancel the select operation by using the Cancel
  45.         ' property. For this example, if the user selects a customer with
  46.         ' the ID "ANATR", the select operation is canceled and an error message
  47.         ' is displayed.
  48.         If row.Cells(1).Text = "ANATR" Then
  49.  
  50.             e.Cancel = True
  51.             Label2.Text = "You cannot select " + row.Cells(1).Text & "."
  52.  
  53.         End If
  54.  
  55.     End Sub
  56.  
  57. </script>
  58.  
  59. <html xmlns="http://www.w3.org/1999/xhtml" >
  60.   <head id="Head1" runat="server">
  61.     <title>GridView Select Example</title>
  62. </head>
  63. <body>
  64.     <form id="form1" runat="server">
  65.  
  66.      <h3>Trabajadores jubilables mayores de 55 años con más de 25 años trabajando</h3>
  67.  
  68.      <asp:gridview id="CustomersGridView"
  69.        datasourceid="CustomersSource"
  70.        autogeneratecolumns="False"
  71.        autogenerateselectbutton="True"
  72.        allowpaging="True"
  73.        selectedindex="1"
  74.        onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
  75.        onselectedindexchanging="CustomersGridView_SelectedIndexChanging"  
  76.        runat="server" DataKeyNames="rpe" BackColor="LightGoldenrodYellow"
  77.          BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
  78.          GridLines="None">
  79.  
  80.          <AlternatingRowStyle BackColor="PaleGoldenrod" />
  81.  
  82.          <Columns>
  83.              <asp:BoundField DataField="rpe"
  84.                  HeaderText="RPE del Empleado"
  85.                  InsertVisible="False" ReadOnly="True"
  86.                  SortExpression="b_contra.fe_repro" />
  87.              <asp:BoundField DataField="nombre"
  88.                  HeaderText="Nombre del Empleado"
  89.                  SortExpression="c_zonas.nombre" />
  90.              <asp:BoundField DataField="Edad"
  91.                  HeaderText="Edad del Empleado"
  92.                  SortExpression="fe_inic" />
  93.                  <asp:BoundField DataField="nombrezona"
  94.                  HeaderText="Nombre de la Zona"
  95.                  SortExpression="fe_inic" />
  96.                  <asp:BoundField DataField="area"
  97.                  HeaderText="Area en que labora"
  98.                  SortExpression="fe_inic" />
  99.                  <asp:BoundField DataField="puesto"
  100.                  HeaderText="Puesto"
  101.                  SortExpression="fe_inic" />
  102.                  <asp:BoundField DataField="fe_natra"
  103.                  HeaderText="Fecha de Nacimiento"
  104.                  SortExpression="fe_inic" />
  105.                  <asp:BoundField DataField="fe_antre"
  106.                  HeaderText="Fecha de Antigüedad Reconocida"
  107.                  SortExpression="fe_inic" />
  108.                  <asp:BoundField DataField="fe_ingre"
  109.                  HeaderText="Fecha de Ingreso"
  110.                  SortExpression="fe_inic" />
  111.                  <asp:BoundField DataField="ubicacion"
  112.                  HeaderText="Ubicación"
  113.                  SortExpression="fe_inic" />
  114.                  <asp:BoundField DataField="nides"
  115.                  HeaderText="nides"
  116.                  SortExpression="fe_inic" />
  117.                  <asp:BoundField DataField="nire"
  118.                  HeaderText="nire"
  119.                  SortExpression="fe_inic" />
  120.                  <asp:BoundField DataField="fe"
  121.                  HeaderText="Fecha Probable de Jubilación"
  122.                  SortExpression="fe_inic" />
  123.                  <asp:BoundField DataField="anyjub"
  124.                  HeaderText="Años Transcurridos Desde la jubilación"
  125.                  SortExpression="fe_inic" />
  126.                  <asp:BoundField DataField="fepos"
  127.                  HeaderText="Fecha Probable Para Jubilación"
  128.                  SortExpression="fe_inic" />
  129.          </Columns>
  130.  
  131.          <FooterStyle BackColor="Tan" />
  132.          <HeaderStyle BackColor="Tan" Font-Bold="True" />
  133.          <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
  134.              HorizontalAlign="Center" />
  135.  
  136.        <selectedrowstyle backcolor="DarkSlateBlue"
  137.          forecolor="GhostWhite"/>  
  138.  
  139.          <SortedAscendingCellStyle BackColor="#FAFAE7" />
  140.          <SortedAscendingHeaderStyle BackColor="#DAC09E" />
  141.          <SortedDescendingCellStyle BackColor="#E1DB9C" />
  142.          <SortedDescendingHeaderStyle BackColor="#C2A47B" />
  143.  
  144.      </asp:gridview>
  145.  
  146.       <br/>
  147.          <asp:label id="Label1"
  148.         forecolor="Red"
  149.         runat="server"/>
  150.          <asp:label id="Label2"
  151.         forecolor="Red"
  152.         runat="server"/>
  153.  
  154.       <!-- This example uses Microsoft SQL Server and connects  -->
  155.       <!-- to the Northwind sample database. Use an ASP.NET     -->
  156.       <!-- expression to retrieve the connection string value   -->
  157.       <!-- from the Web.config file.                            -->
  158.       <asp:sqldatasource id="CustomersSource"
  159.         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"
  160.         connectionstring="server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no"
  161.         runat="server"/>
  162.     <ASP:DataGrid id="MyDataGrid" runat="server"
  163.     Width="700px"
  164.     BackColor="LightGoldenrodYellow"
  165.     BorderColor="Tan"
  166.     CellPadding=2
  167.     Font-Name="Verdana"
  168.     Font-Size="8pt"
  169.     HeaderStyle-BackColor="#aaaadd"
  170.     EnableViewState="False" BorderWidth="1px" Font-Names="Verdana"
  171.          ForeColor="Black" GridLines="None"
  172.   >
  173.         <AlternatingItemStyle BackColor="PaleGoldenrod" />
  174.         <FooterStyle BackColor="Tan" />
  175. <HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>
  176.         <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
  177.             HorizontalAlign="Center" />
  178.         <SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
  179.      </asp:DataGrid>
  180.     </form>
  181.    
  182.   </body>
  183. </html>

Gracias de antemano...