Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/06/2010, 18:47
Avatar de jaullo
jaullo
 
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: 2 commandfield en un gridview!

Porque necesitas dos commandfield. Por un maestro detalle?

Utiliza la propiedad commandname y el elemento ButtonField en lugar del commandfield

Código ASP:
Ver original
  1. <asp:GridView runat="server" OnRowCommand="RowCommandHandler">
  2. <asp:ButtonField CommandName="Select1" Text="Select" />
  3. <asp:ButtonField CommandName="Select2" Text="Select" />
  4. </asp:GridView>

Luego en el código behind

Código ASP:
Ver original
  1. protected void RowCommandHandler(object sender, GridViewRowEventArgs e)
  2. {
  3. if(e.CommandName = "Select1")
  4. {
  5. // Do selects for the first datagrid
  6. }
  7. else
  8. {
  9. // Do selects for the second datagrid
  10. }

Tambien puedes obtener una referencia a la fila que dispará el evento
Código ASP:
Ver original
  1. protected void RowCommandHandler(object sender, GridViewRowEventArgs e)
  2. {
  3. int rowIndex = Convert.ToInt32(e.CommandArgument);
  4. GridViewRow selectedRow = (sender as GridView).Rows[rowIndex];
  5. }

o colocas el CommandArgument como parte de tu databind. Cuando estoy haciendo algo como esto usualmente coloco el CommandArgument de mi button(x) como la clave principal del elemento hijo que deseo seleccionar de la siguiente forma

Código ASP:
Ver original
  1. protected void RowCommandHandler(..)
  2. {
  3. int childKey = Convert.ToInt32(e.CommandArgument);
  4. if(e.CommandName="FirstCommand")
  5. {
  6. SelectSomeDataForTheFirstCommand(childKey);
  7. }
  8. }

Espero esto te ayude