[Webgrid]–selecterow-(Get Selected Row from ASP. NET MVC 3 WebGrid)

Source: Internet
Author: User

Get Selected Row from ASP. MVC 3 WebGrid

Abstract: The following article demonstrates how to get the selected row from the ASP 3 WebGrid and what does to display DA Ta.

Every website have to display data and every website have a Grid control. in ASP. NET MVC 3 There's the WebGrid, which is part of the Microsoft Web Helpers Library. This can is downloaded through NuGet (formerly Nupack). NuGet is a free open source Package Manager This makes it easy-to-find, install, and use the. NET libraries in your PR Ojects. One piece of functionality is critical are reacting when the user selects a item in the WebGrid. This article would focus on finding out which row were selected, but also how to find out more about the the data-is select Ed.

Before moving on, you need to download ASP 3. Click here to download and install them using the Microsoft Web Platform Installer.

Open Studio and create a new ASP. 3 Web Application (Razor) project. To focus on the answer, I ' ve got a simple model as seen below.

Using the WebGrid, it's easy-to-display this data to the user.

The first column is the key to making. @item. Getselectlink outputs a HTML anchor tag with the row selected. This is passed as aquerystring, and the name of the QueryString are set by the Selectionfieldname property set on the grid.

To find out what row is selected are just as easy. The WebGrid has a property called Selectedrow. This sets a reference to a GridViewRow object, represents the selected row in the control. When you combine this and the Hasselection property, you can get the selected row like this.

I ' ve created a partial view called _person.cshtml. The file begins with a underscore (_) because I don ' t want this file called directly from the web. The second parameter is the data being passed into the partial view. The data in this instance is the selected row.

The partial view has and then got access to all the data in the selected row. Nice and easy. Thanks microsoft!!

The entire source code of this article can is downloaded over here

[Webgrid]–selecterow-(Get Selected Row from ASP. NET MVC 3 WebGrid)

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.