How to get datakeys value in a gridview
<p>I try to delete a record in Gridview and Database .I added a boundfield button and set the CommandName to <strong>Deleterecord</strong> in the RowCommand event  I want to get the primary key of this record to delete that(primary key value does not show in the grid view. The following block of code shows this event(I try to show some data in a text box):</p>

<pre><code>protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "Deleterecord")
            {
                TextBox1.Text = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString(); 
                   //bla bla
            }
        }
</code></pre>

<p>I also set </p>

<pre><code>DataKeyName="sourceName"
</code></pre>

<p>in the gridview but it is not my primary key</p>

<p>If I click this button an exception occured like this:
<strong>Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index</strong>
How can I solve this problem</p>
