Gettign data values when bound to ObjectDataSource

6 posts, 0 answers
  1. david
    david avatar
    34 posts
    Member since:
    May 2008

    Posted 16 Jun 2008 Link to this post

    I am trying to get some cell data from a grid that is bound to an ObjectDataSource.

    In the ItemCommand event, when the CommandName is RowClick, I am trying to access e.Item.OwnerTableView.DataKeyValues but there are no columns on the OwenerTableView and no values in DataKeyValues.

    It really seems to me like the Telerik controls, great as they are, are not very well made for some scenarios - ie ObjectDataSource.

    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Jun 2008 Link to this post

    Hi David,

    Try the following code snippet.

    CS:
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "RowClick") 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                string strKey = item.GetDataKeyValue("CustomerID").ToString(); 
            } 
       } 



    Thanks
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. david
    david avatar
    34 posts
    Member since:
    May 2008

    Posted 17 Jun 2008 Link to this post

    Hi Shinu,

    I have tried that, but my columns do no seem to exist:

    'item.GetDataKeyValue("RR_REP")' threw an exception of type 'System.ArgumentOutOfRangeException'

    If I look in e.Item.OwnerTableView my columns are in the AutoGeneratedColumns array but not in the Columns array. The Unique name of the column there is correct - "RR_REP".

    Thanks.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Jun 2008 Link to this post

    Hi David,

    Have you set "RR_REP" as the DataKeyName? Try setting it as the DataKeyName as shown below.

    ASPX:
    <MasterTableView   DataKeyNames="RR_REP" > 

    Thanks
    Shinu.
  6. david
    david avatar
    34 posts
    Member since:
    May 2008

    Posted 18 Jun 2008 Link to this post

    Yes that works thanks.

    How do you get non key columns though? Or does it not matter if you add non key columns to the KeyColumnNames list?

    I guess there must be some documentation that I have not seen that explains all of this, can you point me to where that is located? I think a lot of my problems must be due to the fact that I have missed some important doc file somwhere - I have pretty much only seen the examples.

    Thanks
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Jun 2008 Link to this post

    Hi David,

    Refer the following help document links.

    Retrieving primary key field values for selected items
    Accessing cells and rows

    Thanks
    Shinu.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017