Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:48:51+00:00 2026-06-09T18:48:51+00:00

I have this datagrid <DataGrid Grid.Row=3 Name=DataGrid6S AutoGenerateColumns=False VerticalScrollBarVisibility=Auto> <DataGrid.Columns> <DataGridTextColumn Header=ID Width=50 Binding={Binding

  • 0

I have this datagrid

<DataGrid Grid.Row="3" Name="DataGrid6S" AutoGenerateColumns="False" VerticalScrollBarVisibility="Auto">
    <DataGrid.Columns>
    <DataGridTextColumn Header="ID" Width="50" Binding="{Binding ID}" Visibility="Collapsed"></DataGridTextColumn>
        <DataGridTextColumn Header="Name" Width="200" Binding="{Binding Name}"></DataGridTextColumn>
        <DataGridTextColumn Header="Text" Width="200" Binding="{Binding Text}"></DataGridTextColumn>
        <DataGridTemplateColumn Header="Edit" Width="*">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Button Click="Button_Click" >View Details</Button>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

which is populated by the following code:

class Test {
        public int W { get; set; }
        public string X { get; set; }
        public string Y { get; set; }
    }

public partial class MainWindow : Window {
    public MainWindow() {
        InitializeComponent();

        List<Test> testList = new List<Test>();
        testList.Add(new Test() { W = 0, X = "hello", Y = "one" });
        testList.Add(new Test() { W = 1, X = "hello", Y = "two" });
        testList.Add(new Test() { W = 2, X = "hello", Y = "three" });
        testList.Add(new Test() { W = 3, X = "hello", Y = "four" });

        var query =
            from values in testList
            select new { ID = values.W, Name = values.X, Text = values.Y };

        DataGrid6S.ItemsSource = query;

    }

    private void Button_Click(object sender, RoutedEventArgs e) {
        var obj = ((FrameworkElement)sender).DataContext;
        // Can't access values because it's of an anoymous type.
        // What do I have to do to be able to access the values stored here?

    }
}

When a button is clicked, I’d like to know the ID of the row on which that button was clicked, but I can’t find out because the rows are initialized with anonymous types, what do I have to do to find out the ID of the clicked row?

note: This is a simplified version assume that query consists of 5 joins & a where clause.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:48:52+00:00Added an answer on June 9, 2026 at 6:48 pm

    Just create a named type and select instances of that, anonymous types are for objects that are only edited within the scope in which they are created. Also why not use the Test class directly? The only difference are property names. Also do not forget to cast the DataContext to your named type as it is an object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the control placed in DataGrid like this: <Label Name=lblDescription HorizontalAlignment=Left Margin=0,5,0,0 Grid.Row=2
I have a Datagrid which looks as under <asp:GridView ID=dgTask runat=server Width=100% AutoGenerateColumns=False> <Columns>
I'm having a small problem. I have this grid with a column: <data:DataGrid ColumnHeaderStyle={StaticResource
I have this tiny little issue with the datagrid. In my grid I have
I have a datagrid that displays items with two columns of text row data
BackGround: I have an advanced data grid. The data provider for this ADG is
I have followed this tutorial which allowed me to create a Silverlight DataGrid that
I am new to Flash and AS3. I have a DataGrid like this Item
I have a datagrid who's ItemsSource is a strongly typed IEnumerable object In this
I have a flex datagrid with 3 columns. The first column contains the image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.