title: Get class from Template in a method in C#
body: <p>I need to pass <code>GridViewCommandEventArgs</code> or <code>GridViewRowEventArgs</code> or <code>int</code> in a Generic method and want to get the values out of it.</p>
  
  <p>Example code:</p>
  
  <pre><code>public struct RemarkStruct
  {
      public string remarkId;
  
      public RemarkStruct(string _remarkId)
      {
          remarkId = _remarkId;
      }
  }
  
  public RemarkStruct GetRemarkData&lt;T&gt;(T val)
  {
  
      if (val is GridViewCommandEventArgs )
      {
          GridViewCommandEventArgs gvCommandArgs = (GridViewCommandEventArgs) val;
  
          int rowIndex = GetRowIndex_CommandEvent((T) val);
          //
          GridViewRow row = ((GridViewRow)(((ImageButton)gvCommandArgs.CommandSource).NamingContainer));
          remarkId = (row.FindControl("imgBtnDelete") as ImageButton).CommandArgument;
  
          RemarkStruct remStruct = new RemarkStruct(remarkId);
          return remStruct;
      }
  }
  </code></pre>
  
  <p>And I want to call from the below method.</p>
  
  <pre><code>protected void gvRemark_RowCommand (object sender, GridViewCommandEventArgs e)
  {
      GetRemarkData&lt;GridViewCommandEventArgs &gt;(e);
  }
  </code></pre>
  
  <p>I have just written the code for <code>GridViewCommandEventArgs</code> similarly I want to write for <code>GridViewRowEventArgs</code> and for int also.</p>