Home > DeveloperSection > Forums > How to access row data from a MouseLeftButtonDown event on a textblock, in a gridview
Ankit Singh

Total Post:341

Posted on    February-24-2015 3:56 AM

 ASP.Net .NET  ASP.Net  HTML  Mvc  Gridview 

 1 Reply(s)
 524  View(s)
Rate this:

I am trying to modify data in rows in a gridview which I have pulled from a database.

The data is being bound to each gridview column like the following.

<GridViewColumn Header="Status"
Width="120" util:GridViewSort.PropertyName="Status">
            <TextBlock Text="{Binding Path=Status}" FontWeight="Bold" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown_1"/>

I have a MouseLeftButtonDown event on the textblock, and this fires when I click on the specific text.


private void TextBlock_MouseLeftButtonDown_1(object sender,
MouseButtonEventArgs e)

The issue I am having is that I can't find a way to access the row data(such as the id, or the text in the row).

Is there any way to access all the row data from within the click event?


Goti Bandu

Total Post:119

Posted on    February-24-2015 5:10 AM

Try This:

  private void TextBlock_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        TextBlock textBlock = (sender as TextBlock);
        string text = textBlock.Text;// Text in the TextBlock
        object datacontext = textBlock.DataContext; // datacontext, Entire row info

Don't want to miss updates? Please click the below button!

Follow MindStick