Silverlight obtains the row data selected by the DataGrid.

Source: Internet
Author: User
When I was doing a small demo today, a buddy in the group asked how to obtain the row data of the currently selected DataGrid. By the way, I tested it, we found that Sl is much more convenient than aspx! If the data you bind is entity, you can obtain the entity based on the current selected DataGrid. Code Paste.
Note that the trigger event is currentcellchanged.
Background code:
/// <Summary>
/// Obtain the selected cell data of the DataGrid
/// If the bound data source is an object, the selected current record is an object by default.
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void dgcate_currentcellchanged (Object sender, eventargs E)
{
DataGrid grid = sender as DataGrid;
Bookservice. Book = (bookservice. Book) grid. selecteditems [0]; // obtain the currently selected row data and convert it to the corresponding entity
MessageBox. Show (book. Title. tostring (); // print the attribute value of the object.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.