title: Get SelectedItem value from DataGrid
body: <p>I have a <strong>DataGrid</strong> in my <strong>WPF</strong> application as below.</p>
  
  <pre><code>&lt;DataGrid Name="stDataGrid" AutoGenerateColumns="False"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTemplateColumn Header="Edit" CanUserResize="False" Width="SizeToHeader"&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Button" Click="btnEdit_Click"&gt;
                          &lt;StackPanel&gt;
                              &lt;Image Source="images/edit.png"/&gt;
                          &lt;/StackPanel&gt;
                      &lt;/Button&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" IsReadOnly="True"&gt;&lt;/DataGridTextColumn&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=Age}" Header="Age" IsReadOnly="True"&gt;&lt;/DataGridTextColumn&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=Sex}" Header="Sex" IsReadOnly="True"&gt;&lt;/DataGridTextColumn&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>Binding data into DataGrid like this.</p>
  
  <pre><code>using (var context = new CLASS_DBEntities())
  {
  var query = from s in context.STUDENT
              orderby s.STUDENT_NAME
              select new {s.STUDENT_ID, Name = s.STUDENT_NAME, Age = s.STUDENT_AGE, 
                          Sex = s.STUDENT_SEX};
  
  stDataGrid.ItemsSource = query.ToList();
  }
  </code></pre>
  
  <p>When user click Button in DataGrid, I need to get <code>STUDENT_ID</code> value. How can i do this ?</p>