![]() Clicking the Select button causes a postback. Note that the GridView lists the name and price for all of the products along with a Select LinkButton. Let's view our progress thus far through a browser. ![]() Take a moment to ensure that your GridView's DataKeyNames property is set to ProductID. However, for the selectable GridView in this tutorial, as well as for future tutorials in which we'll be examining inserting, updating, and deleting, the DataKeyNames property must be set properly. While this property has been set for us automatically in the preceding tutorials, the examples would have worked without the DataKeyNames property specified. The DataKeyNames property is automatically set to the uniquely-identifying data field(s) when you bind a data source to a GridView, DetailsView, or FormView through the Designer. The SelectedValue property returns the value of the first DataKeyNames data field for the selected row where as the SelectedDataKey property returns the selected row's DataKey object, which contains all of the values for the specified data key fields for that row. The DataKeyNames property is used to associate one or more data field values with each row and is commonly used to attribute uniquely identifying information from the underlying data with each GridView row. The SelectedIndex property returns the index of the selected row, whereas the SelectedValue and SelectedDataKey properties return values based upon the GridView's DataKeyNames property. In addition to the SelectedRow property, the GridView provides the SelectedIndex, SelectedValue, and SelectedDataKey properties. When a GridView row's Select button is clicked a postback ensues and the GridView's SelectedRow property is updated. By default, the Select buttons are rendered as LinkButtons, but you can use Buttons or ImageButtons instead through the CommandField's ButtonType property. This results in a Select button for each row of the GridView, as Figure 6 illustrates. To accomplish this, simply check the Enable Selection checkbox in the GridView's smart tag.įigure 6: Make the GridView's Rows Selectable ( Click to view full-size image)Ĭhecking the Enabling Selection option adds a CommandField to the ProductsGrid GridView with its ShowSelectButton property set to True. ![]() Next, we need to mark the GridView as selectable, which will add a Select button to each row. These steps can be accomplished graphically, by clicking the Edit Columns link from the GridView's smart tag, or by manually configuring the declarative syntax.įigure 5: Remove All But the ProductName and UnitPrice BoundFields ( Click to view full-size image) Also, feel free to customize these BoundFields as needed, such as formatting the UnitPrice BoundField as a currency and changing the HeaderText properties of the BoundFields. Next, add a new ObjectDataSource named AllProductsDataSource that invokes the ProductsBLL class's GetProducts() method.įigure 2: Create an ObjectDataSource Named AllProductsDataSource ( Click to view full-size image)įigure 3: Use the ProductsBLL Class ( Click to view full-size image)įigure 4: Configure the ObjectDataSource to Invoke the GetProducts() Method ( Click to view full-size image)Įdit the GridView's fields removing all but the ProductName and UnitPrice BoundFields. Start by adding a GridView control to the DetailsBySelecting.aspx page in the Filtering folder, setting its ID property to ProductsGrid. The GridView control can be configured to include a Select button for each row that causes a postback and marks that row as the GridView's SelectedRow. For the single page master/details report, we will need a Button for each GridView row that, when clicked, shows the details. Such a hyperlink was added to each GridView row using a HyperLinkField. Recall that in the two-page master/detail report that each master record included a hyperlink that, when clicked, sent the user to the details page passing the clicked row's SupplierID value in the querystring. Clicking the Select button for a particular product will cause its full details to be displayed in a DetailsView control on the same page.įigure 1: Clicking the Select Button Displays the Product's Details ( Click to view full-size image) Step 1: Creating a Selectable GridView This tutorial will have a GridView whose rows include the name and price of each product along with a Select button. This two page report format can be condensed into one page. In the previous tutorial we saw how to create a master/detail report using two web pages: a "master" web page, from which we displayed the list of suppliers and a "details" web page that listed those products provided by the selected supplier. Clicking the Select button for a particular product will cause its full details to be displayed in a DetailsView control on the same page.
0 Comments
Leave a Reply. |