asp.net.ph

GridView.SelectedValue Property

System.Web.UI.WebControls Namespace   GridView Class


.NET Framework version 2.0

Returns the data key value of the selected row in a GridView control.

Syntax


Script GridView.SelectedValue [ = objDataKeyvalue ]

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


objDataKeyvalue An object specifying the data key value of the selected row in a GridView control.

The property is read only with no default value.

Remarks

Use the SelectedValue property to determine the value of the row selected by the user in the GridView control.

Example

The following example demonstrates how to use the SelectedValue property to determine the data key value of the selected row in a GridView control.

In this example, the GridView's SelectedValue property is defined as a parameter for the SelectCommand of a SqlDataSource control bound to a FormView control. This value is used by the data source control provider to specify which row to fetch in the data source and bind to the FormView.

<asp:sqldatasource id = "bookDetails" runat = "server"
   datasourcemode = "datareader"
   selectcommand = "SELECT * FROM pubs_Titles WHERE title_id = @title_id"
   connectionstring = "<%$ ConnectionStrings:aspnet %>">

   <selectparameters>
      <asp:controlparameter controlid = "gvTitles" 
         name = "title_id" type = "string"
         propertyname = "SelectedValue" />
   </selectparameters>
</asp:sqldatasource>
Run Sample | View Source
See Also

SelectedDataKey   SelectedRow   Allowing Users to Select Rows in a GridView Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph