Fire Client Side Select Event On Server Side

3 posts, 1 answers
  1. Vince Ockerman
    Vince Ockerman avatar
    5 posts
    Member since:
    May 2010

    Posted 30 Jan 2011 Link to this post

    I have a grid where "OnRowSelected" I fire a javascript function that moves the selection's data to another part of the screen, it works kind of like an old school windows multi-select slide over box. This is working fine, and I have no issues with it.

    My problem is that this is all part of a data item that can be saved and edited later. In the event that the user wishes to edit the item later, I need to load in the grid with the data items pre-selected. I know how to do that, and have that part working.

    My question is: Is there an easy way to fire my client-side events after I bind the grid and force selection server side, so that the UI will look as if the user clicked the selections (all my javascript gets executed is my main goal here). I'd like to send all the selection code down the same funnel, so that the de-select code all functions properly in the aforementioned scenario.

    I am trying to avoid postbacks, ajax or otherwise, as my users' machines are very old, and even nicely setup update panels and ajaxmanagers seem to take forever to execute.

  2. Answer
    Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 03 Feb 2011 Link to this post

    Hello Vince,

    To achieve the desired functionality you could try registering startup script on the server, which calls client side javascript function. This function gets as parameter all rows' indexes which need to be selected. Also into the function you could get the item by its index and select it. This will fire the OnRowSelected event. For example:
    ASPX.CS
    string script = string.Format("SelectItems({0})", "['1','2']");
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SelectItems", script, true);
    ASPX
    function SelectItems(itemsIndexes)
     {
             setTimeout(function ()
             {
                    var masterTable = $find("<%=RadGrid1.ClientID %>").get_masterTableView();
                    var dataItems = masterTable.get_dataItems();
                    for (var i = 0; i < itemsIndexes.length; i++)
                    {
                        var item = dataItems[itemsIndexes[i]].get_element();
                        masterTable.selectItem(item);
                    }
                }, 300);
       }

    Additionally I am sending you a simple example which demonstrates the desired functionality. Please check it out and let me know if it helps you.

    Regards,
    Radoslav
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vince Ockerman
    Vince Ockerman avatar
    5 posts
    Member since:
    May 2010

    Posted 03 Feb 2011 Link to this post

    Thank you - exactly what I was looking for.
Back to Top