Getting Value of particular key in gridview datakeys

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Getting Value of particular key in gridview datakeys

Post by jmestep » Fri Feb 06, 2009 12:36 pm

I'm adapting the EditSimilarProducts.ascx to use to link webpages of a custom type to a product.
The SearchResultsGrid now has three data keys, CategoryId, CatalogNodeId, CatalogNodeTypeId.

The RelatedProductGrid has 4 keys, objectId1, objecctType1, objectId2, objectType2

When I add/remove a link, the objectId1 is the parent productId and the objectType1 is 1 since it's a product.
I need to map the CatalogNodeId to the objectId2 and the CatalogNodeTypeId to the objectType2.
I'm changing the following:

Code: Select all

 protected void RelatedProductGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int relatedProductId = (int)e.Keys[0];
        SetLink(relatedProductId, false);
        //CHECK THE SEARCH RESULTS GRID TO SEE IF THIS ITEMS APPEARS
        int tempIndex = 0;
        foreach (DataKey key in SearchResultsGrid.DataKeys)
        {
            int tempId = (int)key.Value;
            if (relatedProductId == tempId)
to

Code: Select all

protected void RelatedObjectGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       int relatedObjectId = (int)e.Keys[2];
       int relatedType = (int)e.Keys[3];
       SetLink(relatedObjectId,relatedType, false);
        //CHECK THE SEARCH RESULTS GRID TO SEE IF THIS ITEMS APPEARS
        int tempIndex = 0;
          int tempId = (int)SearchResultsGrid.DataKeys[1].Value;
         int tempType = (byte)SearchResultsGrid.DataKeys[2].Value;
        
but something is not picking up for the keys for tempId and tempType. The code keeps picking up the CategoryId and saving that to the objectId2 in the database with 0 in the objectType2 field.
Can anyone tell me how to edit the above? I can change the order of the DataKeyNames="CategoryId,CatalogNodeId,CatalogNodeTypeId" to put the CatalogNodeId first and then that gets put into the database OK, but the type doesn't get put in.
Thanks
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Getting Value of particular key in gridview datakeys

Post by mazhar » Mon Feb 09, 2009 6:42 am

Instead of using the below code

Code: Select all

  int tempId = (int)SearchResultsGrid.DataKeys[1].Value;
         int tempType = (byte)SearchResultsGrid.DataKeys[2].Value;
Give a try to the following

Code: Select all

int tempId = (int)SearchResultsGrid.DataKeys[data item index].Value;
int tempType = (byte)SearchResultsGrid.DataKeys[data item index].Value[1];
where data item index is the record index in grid view.

Post Reply