Ticket Q494995
Visible to All Users

Fields value in ASPxGridView on Row Command

created 12 years ago

Hi,
In my ASPxGridView on row command event i am capturing id of row clicked and than reading row values its working fine.
But when i filter the records and click on the link button i am not getting the correct id …by default id is coming as 1
my code:
   object id = e.CommandArgs.CommandArgument;
            string filename = Convert.ToString(grdhdm.GetRowValuesByKeyValue(id, "filename"));

After filtering the records object is coming as 1 and not the correct one and sometimes it returns null and when second time you click the same link it will return the correct value but after filtering on first attempt it does not give correct id
Also pls let me know how i can make the filtering criteria as 'Contains' by default
Regards,
Neeraj

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

Hi Neeraj,
I suggest you use the ASPxGridViewRowEventArgs.KeyValue property to get the row ID.
UPDATED:
The ASPxGridViewRowEventArgs.KeyValue property provides a capability to get an ID value by a key value. Thus, this property allows you to avoid issues with grid filtering and sorting:

C#
protected void gv_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e) { ASPxGridView grid = (ASPxGridView)sender; object id = e.KeyValue; string filename = grid.GetRowValuesByKeyValue(id, "CategoryName").ToString(); }

I've attached a sample project and video to show how it works.

    Show previous comments (2)
    DevExpress Support Team 12 years ago

      The ASPxGridViewRowEventArgs.KeyValue property provides a capability to get an ID value by a key value. Thus, this property allows you to avoid issues with grid filtering and sorting:

      C#
      protected void gv_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e) { ASPxGridView grid = (ASPxGridView)sender; object id = e.KeyValue; string filename = grid.GetRowValuesByKeyValue(id, "CategoryName").ToString(); }

      I've attached a sample project and video to show how it works.

        thanks Demetrius…its working

        DevExpress Support Team 12 years ago

          I am glad to hear that my assistance was helpful.
          Once your question has been resolved to your satisfaction, mark a corresponding Answer as a Solution. Your question status will immediately become Closed.
          SC2 FAQ

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.