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

Access ClientDataKeyValue on button click

1 Answer 90 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Chetan
Top achievements
Rank 1
Chetan asked on 30 Dec 2013, 11:38 PM
I have a radbutton in ItemTemplate of RadListView. I have defined  ClientDataKeyNames="ID" 
Now how do I get the  ClientDataKeyValue "ID" onClientClicked of radbutton? Is it possible to get the index of the ListviewITem on clientside javascript

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 31 Dec 2013, 04:48 AM
Hi Chetan,

Please try the following code snippet get the ClientDataKeyValues of a RadListView on RabButton OnClientClicked event.

ASPX:
<telerik:RadListView ID="RadListView1" Width="97%" AllowPaging="True" runat="server"
    AllowSorting="true" DataSourceID="SqlDataSource1" ItemPlaceholderID="ProductsHolder"
    DataKeyNames="ProductID" ClientDataKeyNames="ProductID" OnItemDataBound="RadListView1_ItemDataBound">
    <LayoutTemplate>
        <fieldset style="max-width: 920px;" id="FieldSet1">
            <legend>Products</legend>
            <asp:Panel ID="ProductsHolder" runat="server" />
        </fieldset>
    </LayoutTemplate>
    <ItemTemplate>
        <telerik:RadButton ID="RadButton1" runat="server" Text="Demo" OnClientClicked="OnClientClicked1">
        </telerik:RadButton>
    </ItemTemplate>
</telerik:RadListView>

C#:
protected void RadListView1_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
{
    if (e.Item is RadListViewDataItem)
    {
        RadListViewDataItem item = e.Item as RadListViewDataItem;
        RadButton btn = item.FindControl("RadButton1") as RadButton;
        btn.Attributes.Add("rowindex", item.DataItemIndex.ToString());
    }
}

JavaScript:
<script type="text/javascript">
    function OnClientClicked1(sender, args) {
        var listview = $find("<%=RadListView1.ClientID %>");
        var index = sender._element.getAttribute("rowindex");
        alert(listview._clientKeyValues[index].ProductID);
    }
</script>

Hope this will helps you.
Thanks,
Shinu.
Tags
ListView
Asked by
Chetan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or