Access ClientDataKeyValue on button click

2 posts, 1 answers
  1. Chetan
    Chetan avatar
    13 posts
    Member since:
    Sep 2012

    Posted 30 Dec 2013 Link to this post

    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.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Dec 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top