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)