Where is the item.itemindex property?

8 posts, 0 answers
  1. Jonathan Simmons
    Jonathan Simmons avatar
    108 posts
    Member since:
    Jun 2005

    Posted 12 Feb 2010 Link to this post

    Hi, I am trying to use a RadListView in the same way I use a RadGrid in that I am trying to get the datakeyvalue for a specific dataitem when in the ItemDataBound method.

    In a RadGrid, I can do the following:

    e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][myDataKey] 

    to get the value of each datakey and then set client-side onclick attributes for a hyperlink so that clicking the link opens a RadWindow, passing in the row ID.

    However, e.Item for a RadListView does not have an ItemIndex property, so how can I do the same for a RadListView?
    ie,

    e.Item.OwnerListView.DataKeyValues[???][myDataKey]

    Regards,
    Jonathan
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 16 Feb 2010 Link to this post

    Hello Jonathan,

    RadListView exposes DisplayIndex property that specifies the order of the item when displayed. Hence you can pass that property value in order to extract the key values for a given RadListViewDataItem, for example:

    C#
    string keyVal = e.Item.OwnerListView.DataKeyValues[e.Item.DisplayIndex]["CustomerID"].ToString();

    VB.NET
    Dim keyVal As String = e.Item.OwnerListView.DataKeyValues(e.Item.DisplayIndex)("CustomerID").ToString()


    Kind regards,
    Sebastian
    the Telerik team


    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jonathan Simmons
    Jonathan Simmons avatar
    108 posts
    Member since:
    Jun 2005

    Posted 16 Feb 2010 Link to this post

    Thanks Sebastian,

    I missed that property in the list.

    Regards,
    Jonathan
  5. Jonathan Simmons
    Jonathan Simmons avatar
    108 posts
    Member since:
    Jun 2005

    Posted 16 Feb 2010 Link to this post

    Sebastian,

    The property e.Item.DisplayIndex only seems to be available during RadListView1_ItemInserted and RadListView1_ItemUpdated but NOT during RadListView1_ItemDataBound.

    This means I still cannot add the attribute I need, ie

     

    (e.Item.FindControl("lnkbEdit"as LinkButton).Attributes.Add("onclick",   
    "OpenwndRM('" + e.Item.OwnerListView.DataKeyValues[ItemIndex]["ResearchMethodID"].ToString() + "');return false;"); 

    This sets the client-side click event to open a RadWindow, passing in the row identifier to the javascript function.

    Regards,
    Jonathan
  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 16 Feb 2010 Link to this post

    Hello Jonathan,

    Can you please confirm that you tried this code inside the ItemDataBound handler:

    Attributes.Add("onclick",   
    "OpenwndRM('" + e.Item.OwnerListView.DataKeyValues[e.Item.DisplayIndex]["ResearchMethodID"].ToString() + "');return false;");

    Also note that the more appropriate place to set the attribute for the link button is the ItemCreated event of RadListView (see this topic for details).

    Best regards,
    Sebastian
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Jonathan Simmons
    Jonathan Simmons avatar
    108 posts
    Member since:
    Jun 2005

    Posted 16 Feb 2010 Link to this post

    Hi Sebastian, here is the code lifted from the code-behind:

     

    protected void RadListView1_ItemDataBound(object sender, RadListViewItemEventArgs e)

     

    {

    (e.Item.FindControl(

    "lnkbEdit") as LinkButton).Attributes.Add("onclick", "OpenwndRM('" + e.Item.OwnerListView.DataKeyValues[e.Item.displayitem]["ResearchMethodID"].ToString() + "');return false;");

     

    }

    The displayitem of e.Item.displayItem is flagged as an unknown member.

    Regards,
    Jonathan

    PS using dll version 2009.3.1314.35

  8. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 16 Feb 2010 Link to this post

    Hello Jonathan,

    The property I am referring to is DisplayIndex, not displayitem. Review the code snippets from my previous posts and let me know if I am leaving something obvious out.

    Regards,
    Sebastian
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Jonathan Simmons
    Jonathan Simmons avatar
    108 posts
    Member since:
    Jun 2005

    Posted 16 Feb 2010 Link to this post

    Hi Sebastian,
    Sorry, my mistake - a simple typo.

    However, I have managed to get it working  by casting e.item as a RadListViewDataItem.

    So this now works:

     

    protected void RadListView1_ItemDataBound(object sender, RadListViewItemEventArgs e)

     

    {

     

    RadListViewDataItem item = (RadListViewDataItem)e.Item;

     

    (e.Item.FindControl(

    "lnkbEdit") as LinkButton).Attributes.Add("onclick", "OpenwndRM('" + e.Item.OwnerListView.DataKeyValues[item.DisplayIndex]["ResearchMethodID"].ToString() + "');return false;");

     

    }


    Thanks for your help.
    Regards,
    Jonathan

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