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

Bueno, ya lo hice usando el RowCommand, y bueno tengo un pequeño conflicto al recibir la variable en el Response.QueryString, lo puse de esta manera:

Request.QueryString["rpe"].ToString() y me genera este error:
Debe asignarse un acceso de propiedad a la propiedad o utilizar su valor.

Lo puse agregandosela a una variable:
Dim cadena = Request.QueryString["rpe"].ToString()
Pero me arroja otro error:
Se esperaba un identificador.

Pensé que esta estaba bien ya que en la query de mi segunda pagina quiero hacerle referencia al trabajador que seleccione y lo hago haciéndole referencia en la misma consulta a la variable consulta:

... AND rpe='" & cadena & "' ...

El código de mis 2 páginas es el siguiente:

Calando3
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 GridViewCommandEventHandler(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
  10.  
  11.         If (e.CommandName = "Detalle") Then
  12.             Response.Redirect("Calando4.aspx?rpe=" + e.CommandArgument.ToString())
  13.         End If
  14.     End Sub
  15.  
  16. </script>
  17.  
  18. <html xmlns="http://www.w3.org/1999/xhtml" >
  19.   <head id="Head1" runat="server">
  20.     <title>GridView Select Example</title>
  21. </head>
  22. <body>
  23.     <form id="form1" runat="server">
  24.  
  25.      <h3>Trabajadores jubilables mayores de 55 años con más de 25 años trabajando</h3>
  26.  
  27.      <asp:gridview id="CustomersGridView"
  28.        datasourceid="CustomersSource"
  29.        autogeneratecolumns="False"
  30.        autogenerateselectbutton="True"
  31.        allowpaging="True"
  32.        OnRowCommand="GridViewCommandEventHandler"  
  33.        runat="server" DataKeyNames="rpe" BackColor="LightGoldenrodYellow"
  34.          BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
  35.          GridLines="None">
  36.      
  37.          <AlternatingRowStyle BackColor="PaleGoldenrod" />
  38.  
  39.          <Columns>
  40.          <asp:TemplateField HeaderText="Detalle" ItemStyle-Width="70px" HeaderStyle-Width="70px">
  41.       <ItemTemplate>
  42.        <asp:LinkButton ID="Lnk_Redireccionar" Text="Incidencias" Style="background-color: Transparent; margin-top: -3px;"
  43.         CommandName="Detalle" runat="server" CommandArgument='<%#Eval("rpe") %>'>
  44.         </asp:LinkButton>
  45.       </ItemTemplate>
  46.       <HeaderStyle Width="70px" />
  47.       <ItemStyle HorizontalAlign="Center" />
  48.      </asp:TemplateField>
  49.              <asp:BoundField DataField="rpe"
  50.                  HeaderText="RPE del Empleado"
  51.                  InsertVisible="False" ReadOnly="True"
  52.                  SortExpression="b_contra.fe_repro" />
  53.              <asp:BoundField DataField="nombre"
  54.                  HeaderText="Nombre del Empleado"
  55.                  SortExpression="c_zonas.nombre" />
  56.                  <asp:BoundField DataField="fechanat"
  57.                  HeaderText="Fecha de Nacimiento"
  58.                  SortExpression="fe_inic" />
  59.                  <asp:BoundField DataField="fechaant"
  60.                  HeaderText="Fecha de Antigüedad Reconocida"
  61.                  SortExpression="fe_inic" />
  62.                  <asp:BoundField DataField="fe"
  63.                  HeaderText="Fecha Probable de Jubilación"
  64.                  SortExpression="fe_inic" />
  65.                  <asp:BoundField DataField="anyjub"
  66.                  HeaderText="Años Transcurridos Desde la jubilación"
  67.                  SortExpression="fe_inic" />
  68.                  <asp:BoundField DataField="fepos"
  69.                  HeaderText="Fecha Probable Para Jubilación"
  70.                  SortExpression="fe_inic" />
  71.          </Columns>
  72.  
  73.          <FooterStyle BackColor="Tan" />
  74.          <HeaderStyle BackColor="Tan" Font-Bold="True" />
  75.          <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
  76.              HorizontalAlign="Center" />
  77.  
  78.        <selectedrowstyle backcolor="DarkSlateBlue"
  79.          forecolor="GhostWhite"/>  
  80.  
  81.          <SortedAscendingCellStyle BackColor="#FAFAE7" />
  82.          <SortedAscendingHeaderStyle BackColor="#DAC09E" />
  83.          <SortedDescendingCellStyle BackColor="#E1DB9C" />
  84.          <SortedDescendingHeaderStyle BackColor="#C2A47B" />
  85.  
  86.      </asp:gridview>
  87.  
  88.       <br/>
  89.          <asp:label id="Label1"
  90.         forecolor="Red"
  91.         runat="server"/>
  92.  
  93.       <asp:sqldatasource id="CustomersSource"
  94.         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, convert(varchar,b_traba1.fe_antre,103) as fechaant, convert(varchar,b_traba1.fe_ingre,103) AS fechaingre, convert(varchar,b_traba3.fe_natra,103) AS fechanat, 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, convert(varchar,fe,103) AS fe, CASE WHEN fe<convert(varchar,GETDATE(),103) THEN convert(varchar,GETDATE(),103) 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, convert(varchar,b_traba1.fe_antre,103)) ELSE DATEADD(yy, 25, convert(varchar,b_traba1.fe_antre,103)) 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"
  95.         connectionstring="server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no"
  96.         runat="server"/>
  97.     <ASP:DataGrid id="MyDataGrid" runat="server"
  98.     Width="700px"
  99.     BackColor="LightGoldenrodYellow"
  100.     BorderColor="Tan"
  101.     CellPadding=2
  102.     Font-Name="Verdana"
  103.     Font-Size="8pt"
  104.     HeaderStyle-BackColor="#aaaadd"
  105.     EnableViewState="False" BorderWidth="1px" Font-Names="Verdana"
  106.          ForeColor="Black" GridLines="None"
  107.   >
  108.         <AlternatingItemStyle BackColor="PaleGoldenrod" />
  109.         <FooterStyle BackColor="Tan" />
  110. <HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>
  111.         <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
  112.             HorizontalAlign="Center" />
  113.         <SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
  114.      </asp:DataGrid>
  115.     </form>
  116.    
  117.   </body>
  118. </html>

Calando4
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 Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
  10.         Dim cadena = Request.QueryString["rpe"].ToString()
  11.         Dim MyConnection As SqlConnection = New SqlConnection("server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no")
  12.         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' OR cl_incid='0670' OR cl_incid='050') AND rpe='" & cadena & "' GROUP BY rpe, cl_incid, fe_inic", MyConnection)
  13.         MyConnection.Open()
  14.  
  15.         Dim dr As SqlDataReader = MyCommand.ExecuteReader()
  16.         MyDataGrid.DataSource = dr
  17.         MyDataGrid.DataBind()
  18.        
  19.     End Sub
  20.  
  21. </script>
  22.  
  23. <html xmlns="http://www.w3.org/1999/xhtml" >
  24.   <head id="Head1" runat="server">
  25.     <title>GridView Select Example</title>
  26. </head>
  27. <body>
  28.     <form id="form1" runat="server">
  29.  
  30.      <h3>Incidencias de los Trabajadores Jubilables</h3>
  31.  
  32.       <br/>
  33.     <ASP:DataGrid id="MyDataGrid" runat="server"
  34.     Width="700px"
  35.     BackColor="LightGoldenrodYellow"
  36.     BorderColor="Tan"
  37.     CellPadding=2
  38.     Font-Name="Verdana"
  39.     Font-Size="8pt"
  40.     HeaderStyle-BackColor="#aaaadd"
  41.     EnableViewState="False" BorderWidth="1px" Font-Names="Verdana"
  42.          ForeColor="Black" GridLines="None"
  43.   >
  44.         <AlternatingItemStyle BackColor="PaleGoldenrod" />
  45.         <FooterStyle BackColor="Tan" />
  46. <HeaderStyle BackColor="Tan" Font-Bold="True"></HeaderStyle>
  47.         <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
  48.             HorizontalAlign="Center" />
  49.         <SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
  50.      </asp:DataGrid>
  51.     </form>
  52.    
  53.   </body>
  54. </html>