title: Retriving cell value from gridview rowcommand
body: <p>hey I'm using to buttons in a gridview each which I want to assign to specific action involves retrieving certain cell values from the gridview columns 
  I tried using</p>
  
  <pre><code> GridViewRow row = (GridViewRow (((Button)e.CommandSource).NamingContainer);
  </code></pre>
  
  <p>but it gives me Unable to cast object of type 'System.Web.UI.WebControls.GridView' to type 'System.Web.UI.WebControls.Button'.</p>
  
  <p>I also tried </p>
  
  <pre><code>int index = Convert.ToInt32(e.CommandArgument);
  GridViewRow row = GridView1.Rows[index];
  </code></pre>
  
  <p>it gives me the following error
  Specified argument was out of the range of valid values.
  Parameter name: index</p>
  
  <p>note that when I tried to specify the commandParameters property of the ButtonField the compiler said that it's not a valid parameter for the ButtomField 
  and I have 8 columns in the gridview so its not out of range</p>
  
  <p>or alternatively could I use more than one select command button 
  if so how to say which one is clicked??  </p>
  
  <p>please help me im desperate  </p>
  
  <p>ASP code:</p>
  
  <pre><code> &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="AcitivityId" DataSourceID="SqlDataSource1" Height="304px" Width="912px" OnRowCommand="GridView1_RowCommand"&gt;
              &lt;Columns&gt;
                  &lt;asp:BoundField DataField="AcitivityId" HeaderText="AcitivityId" InsertVisible="False" ReadOnly="True" SortExpression="AcitivityId" /&gt;
                  &lt;asp:BoundField DataField="ActiviityName" HeaderText="ActiviityName" SortExpression="ActiviityName" /&gt;
                  &lt;asp:BoundField DataField="ActivityLocation" HeaderText="ActivityLocation" SortExpression="ActivityLocation" /&gt;
                  &lt;asp:BoundField DataField="ActivityStartDate" HeaderText="ActivityStartDate" SortExpression="ActivityStartDate" /&gt;
                  &lt;asp:BoundField DataField="ActivityDueDate" HeaderText="ActivityDueDate" SortExpression="ActivityDueDate" /&gt;
                  &lt;asp:BoundField DataField="ActivityDescription" HeaderText="ActivityDescription" SortExpression="ActivityDescription" /&gt;
                  &lt;asp:ButtonField ButtonType="Button" CommandName="Avaliable" Text="Show avaliable buses" /&gt;
                  &lt;asp:ButtonField ButtonType="Button" CommandName="Assigned" Text="Show assigned buses "/&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>