Solved: “ASPxGridView component’s GetSelectedFieldValues method does not retrieving values”

One of the amazing components in DevExpress suite is ASPxGridView. It has a method called GetSelectedFieldValues for retrieving values which are selected by the user. However, you might run into a problem such as retrieving nothing!

Problem with getting selected values in the runtime?
Problem with getting selected values in the run time?

 

Here is the code that you use and fail retrieving data:

Default.aspx.cs:

List<object> fieldValues2 = gridSiteList.GetSelectedFieldValues(new string[] { "column1", "column2" });

Default.aspx:

<dx:ASPxGridView ID="gridSiteList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" Width="297px">
     <Columns>
          <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Width="40px">
          </dx:GridViewCommandColumn>
          <dx:GridViewDataTextColumn FieldName="column1" VisibleIndex="1" Width="130px" Caption="Name">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn FieldName="column2" VisibleIndex="2" Width="130px" Caption="IP">
          </dx:GridViewDataTextColumn>
     </Columns>
</dx:ASPxGridView>

Solution

ASPxGridView needs you to specify the name of a unique column to work correctly. In order to specify it, simply add this parameter into the component definition:

KeyFieldName="column1"

So, the edited ASPX code look like this:

<dx:ASPxGridView ID="gridSiteList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" KeyFieldName="column1" Width="297px">
     <Columns>
          <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Width="40px">
          </dx:GridViewCommandColumn>
          <dx:GridViewDataTextColumn FieldName="column1" VisibleIndex="1" Width="130px" Caption="Name">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn FieldName="column2" VisibleIndex="2" Width="130px" Caption="IP">
          </dx:GridViewDataTextColumn>
     </Columns>
</dx:ASPxGridView>

You don’t need to change anything in CS file.

Upgrading your Visual Studio projects after installing new version of DevExpress

Here is the case:

  • You have already installed DevExpress
  • You have projects which are using DevExpress components on Visual Studio
  • You would like to install new version of DevExpress and using new components at your current projects

visual-studio-devexpress

Here is the remedy:

  • Do not remove previous version of DevExpress!!
  • Install new version. So two versions will be installed at the same time.
  • Upgrade your projects by using ProjectConverter (Start -> All Programs -> Developer Express v2012 vol 2 -> Components -> Tools -> ProjectConverter)
  • Remove previous version

You’re all set!

More information:
http://documentation.devexpress.com/#GeneralInformation/CustomDocument2221