Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Command behind a GridView ButtonField
  2. <asp:ButtonField ButtonType="Image" ImageUrl="~/Images/pdf.png"  CommandName="pdf_click" />
  3.        
  4. protected void pdf_click(object sender, EventArgs e)
  5. {
  6.     lblWelkom.Text = "Succes!";
  7. }
  8.        
  9. void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
  10.  {
  11.  // If multiple buttons are used in a GridView control, use the
  12.  // CommandName property to determine which button was clicked.
  13.  if(e.CommandName=="pdf_click")
  14.   {
  15.    // Convert the row index stored in the CommandArgument
  16.    // property to an Integer.
  17.    int index = Convert.ToInt32(e.CommandArgument);
  18.  
  19.    // Retrieve the row that contains the button clicked
  20.    // by the user from the Rows collection.
  21.    GridViewRow row = ContactsGridView.Rows[index];
  22.    // Now you have access to the gridviewrow.
  23.   }  
  24. }
  25.        
  26. int index = Convert.ToInt32(e.CommandArgument);
  27.     int ServerID = Convert.ToInt32(GridView1.DataKeys[index].Value);