This is a migrated thread and some comments may be shown as answers.

SEO Paging and DataKeyValues

3 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Howard Etheridge
Top achievements
Rank 1
Howard Etheridge asked on 07 Jan 2009, 05:24 PM
I noticed several things when specifying SEO paging. In the ItemDataBound event, the ItemIndex does not correspond to the DataKeyValues. DataKeyValues always start with the first record of your datasource. The CurrentPageIndex is always 0. I'm not sure if this is a bug or something i am not doing correctly.

As a work around i had to write this code to get the datakey:

           int currepagepageindex = 1;
            int itemindex = 0;

            if (Request.QueryString[GrdProducts.ClientID + "ChangePage"] != null)
                currepagepageindex = int.Parse(Request.QueryString[GrdProducts.ClientID + "ChangePage"]);
            
            
            itemindex = currepagepageindex * GrdProducts.PageSize - GrdProducts.PageSize + e.Item.ItemIndex;
            if (itemindex < ((DataTable)GrdProducts.DataSource).Rows.Count)
            {
                inventoryid = (int)((DataTable)GrdProducts.DataSource).Rows[itemindex]["inventoryid"];
            }
                      




3 Answers, 1 is accepted

Sort by
0
Howard Etheridge
Top achievements
Rank 1
answered on 07 Jan 2009, 05:57 PM
another issue, this only occurs when you navigate to next or previous pages:

 ASP.fulfillment_controls_productimage_ascx ProductImage1 = (ASP.fulfillment_controls_productimage_ascx)e.Item.FindControl("ProductImage1");


// this does not work, setting properties have no effect on child controls
ProductImage1.visible = true;

//or this:
ProductImage1.ImageUrl = "someimage.jpg";

I think this has something to do with the CurrentPageIndex being 0.
       



0
Accepted
Georgi Krustev
Telerik team
answered on 10 Jan 2009, 02:52 PM
Hello Howard,

I suppose you set Pager style to MasterTableView. If my assumption right?

To attain the functionality you are searching for, you need to set Pager style to RadGrid.

Here is a code snippet describing this approach:
<telerik:RadGrid ID="RadGrid1" runat="Server"
<PagerStyle Mode="NextPrevAndNumeric" EnableSEOPaging="True" ></PagerStyle
... 
<MasterTableView>...</MasterTableView> 
... 
</telerik:RadGrid> 

Thus the paging will work properly and all issues which you described so far should be resolved.
I just want to specify that ItemIndex has nothing in common with DataKeyValues. The ItemIndex is the index of the current created item which is actually GridRow. DataKeyValues, on other hand, is the values for the specified DataKeyNames of these rows. In your case the "inventoryID".

Below is a code excerpts which shows how to get DataKeyValues:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem)  
        { 
            var DataKeysArray = ((GridDataItem)e.Item).OwnerTableView.DataKeyValues;
        } 
    } 

I hope this explanation is helpful.

Best regards,
Georgi Krustev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Howard Etheridge
Top achievements
Rank 1
answered on 14 Jan 2009, 03:52 PM
Thank you for the response, I tried it on another test page and it appears to be working.
Tags
Grid
Asked by
Howard Etheridge
Top achievements
Rank 1
Answers by
Howard Etheridge
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or