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
7 Answers, 1 is accepted
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.
I missed that property in the list.
Regards,
Jonathan
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
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.
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
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.
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