Ver Mensaje Individual
  #5 (permalink)  
Antiguo 04/01/2010, 16:53
chamako1988
 
Fecha de Ingreso: octubre-2009
Mensajes: 14
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: recoger valor de columna ID y ejecutar evento en boton de gridview

Mira Yo Te Doy Una Mejor respuesta......


Esto es la parte del Html


<asp:GridView id="dgDatos" runat="server" Width="100%" OnPageIndexChanging="dgDatos_PageIndexChanging" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="COD_ACTA_TOLERANCIA" OnRowDataBound="dgDatos_RowDataBound" OnRowCommand="dgDatos_RowCommand" PageSize="20">
<RowStyle CssClass="gridItemGroup"></RowStyle>
<Columns>
<asp:TemplateField><ItemTemplate>
<asp:Label ID="fila" runat="server" Text='<% # Container.DataItemIndex + 1 %>'></asp:Label>

</ItemTemplate>

<ItemStyle HorizontalAlign="Right" Width="15px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="NUMERO_ACTA" HeaderText="NRO. ACTA">
<ItemStyle HorizontalAlign="Center" Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="FECHA_ACTA" HeaderText="F. ACTA">
<ItemStyle HorizontalAlign="Center" Width="90px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="NOMBRE_TIPO_SERVICIO" HeaderText="T. SERVICIO">
<ItemStyle HorizontalAlign="Center" Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="PLACA_RODAJE" HeaderText="PLACA">
<ItemStyle HorizontalAlign="Center" Width="90px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="NOMBRE_REGION_CTL" HeaderText="REGION">
<ItemStyle HorizontalAlign="Center" Width="120px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="NOMBRE_PUNTO_CTL" HeaderText="LUGAR">
<ItemStyle HorizontalAlign="Center" Width="130px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="NRO_EXPEDIENTE" HeaderText="NRO. EXPEDIENTE">
<ItemStyle HorizontalAlign="Center" Width="120px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="USUARIO_LOG" HeaderText="USUARIO">
<ItemStyle HorizontalAlign="Center" Width="120px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField><ItemTemplate>
<asp:ImageButton ID="ImbAsignarPerfil" runat="server" CommandArgument='<% # Container.DataItemIndex %>'
CommandName="Act" ImageUrl="~/Imagen/btnVer.gif" ToolTip="Ver Detalle" />

</ItemTemplate>

<ItemStyle HorizontalAlign="Center" Width="13px"></ItemStyle>
</asp:TemplateField>
</Columns>
<PagerTemplate>
<TABLE style="WIDTH: 100%" cellSpacing=0 cellPadding=0 border=0><TBODY><TR><TD style="WIDTH: 50%" align=left><asp:Label id="lblTotal" runat="server" CssClass="pagina"></asp:Label></TD><TD style="WIDTH: 50%" align=right>&nbsp;<asp:Label id="lblPagina" runat="server" CssClass="pagina"></asp:Label>&nbsp; <asp:Button id="Button4" runat="server" CssClass="primero" ToolTip="Prim. Pág" CommandArgument="First" CommandName="Page"></asp:Button>&nbsp;<asp:Button id="Button1" runat="server" CssClass="anterior" ToolTip="Pág. anterior" CommandArgument="Prev" CommandName="Page"></asp:Button>&nbsp;<asp:Button id="Button2" runat="server" CssClass="siguiente" ToolTip="Sig. página" CommandArgument="Next" CommandName="Page"></asp:Button>&nbsp;<asp:Button id="Button3" runat="server" CssClass="ultimo" ToolTip="Últ. Pág" CommandArgument="Last" CommandName="Page"></asp:Button></TD></TR></TBODY></TABLE>
</PagerTemplate>

<PagerStyle CssClass="gridPage"></PagerStyle>
<EmptyDataTemplate>
<asp:Label ID="vacio" runat="server" Font-Names='Arial' Font-Size='8pt' Text='NO SE ENCONTRARON RESULTADOS'></asp:Label>
</EmptyDataTemplate>

<SelectedRowStyle CssClass="selectedItem"></SelectedRowStyle>

<HeaderStyle CssClass="gridHead"></HeaderStyle>
</asp:GridView>



Luego Te Pongo los Eventos


protected void dgDatos_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName.Equals("Act"))
{
#region "ObtenerPágina"

Int32 index = Convert.ToInt32(e.CommandArgument);
GridViewRow row;
if (dgDatos.PageIndex == 0)
{
row = dgDatos.Rows[index];
}
else
{
Int32 totalPag = Convert.ToInt32(dgDatos.PageCount);
Int32 itemActl = (totalPag - (totalPag - Convert.ToInt32(dgDatos.PageIndex))) * Convert.ToInt32(dgDatos.PageSize);
row = dgDatos.Rows[index - itemActl];
}
DataKey key = dgDatos.DataKeys[row.RowIndex];

#endregion

//Aqui recuperas tu id y lo mandas hacia tu metodo que quieres llenar o al //response redirect tbn puede ser en esta caso es un método

LlenarDetalle(Convert.ToInt32(key.Value));
}
}
catch (ManagerException)
{
ShowErrorMessage();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
Publish(ex, String.Empty);
ShowErrorMessage();
}
}


y Luego el evento de la paginacion



protected void dgDatos_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
if (e.NewPageIndex != -1)
{
lblEspacio.Text = "";
//PAGINAMOS EL GRIDVIEW
dgDatos.PageIndex = e.NewPageIndex;
//
dgDatos.DataSource="tu datatable";
dgDatos.DataBind();

}
}
catch (ManagerException)
{
ShowErrorMessage();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
Publish(ex, String.Empty);
ShowErrorMessage();
}
}