How to Open Radwindow from Command Item Template for both Insert and Edit..

9 posts, 0 answers
  1. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 04 Mar 2010 Link to this post

    Folks,

    Environment: RadControls for ASP.NET AJAX Q3 2009 / VS 2008 SP1/IE7/WINXP SP 2.

    Is it possible to open Rad Window from Radgrid CommandItemTemplate for both Insert and Update. I would like to customize this page (Window / Edit Dialog for RadGrid: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window). 

    Thanks

    gc_0620

    below is my commanditemtemplate:

    <CommandItemTemplate> 
     <div style="padding: 5px 5px;">  
     Custom command item template for Grid&nbsp;&nbsp;&nbsp;&nbsp;  
     <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected"   
     Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" /> Edit selected</asp:LinkButton>&nbsp;&nbsp;  
     <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Update.gif" /> Update</asp:LinkButton>&nbsp;&nbsp;  
     <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Cancel.gif" /> Cancel editing</asp:LinkButton>&nbsp;&nbsp;  
     ''''  
     ''''  
      New Link Button or href to add new rows via Radwindow->Radgrid.                          
      New Link Button or href to edit existing rows via Radwindow->Radgrid.  
      For Editing existings rows, the Visible property should be: Visible='<%# RadGrid1.EditIndexes.Count == 0 %>',  
      the same as above LinkButton 
    ID="btnEditSelected".  My intention is prior to editing, users must select a Row from current RadGrid..
      ''''
      ''''
    </
    div> 
    </CommandItemTemplate> 
     
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Mar 2010 Link to this post

    Hello,

    You can directly attach the client onclick event to the LinkButtons for update/insert. Then in the event handler (for update button) access the RadGrid and get the selected item and keyvalue from client side. You can use the following client code to get the selected row.

    javascript:
     
    var grid = $find("<%=RadGrid1.ClientID %>"); 
    var MasterTable = grid.get_masterTableView(); 
    var selectedRows = MasterTable.get_selectedItems(); 
    var row = selectedRows[0]; 

    Then open the radwindow using same approach described in the online demo, by passing the parameters.

    Please let me know if you have any doubts in my suggestion,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 05 Mar 2010 Link to this post

    Shinu,

    I am sorry I did not understand your suggestion completely.  All I want is to move this EditLink in commandItemTemplate with its existing functionality remains the same as in this Telerik Example. 


    Thanks 

    GC_0620
    ____________

     <telerik:GridTemplateColumn
                                UniqueName="TemplateEditColumn">
                                <ItemTemplate>
                                    <asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <CommandItemTemplate>
                            <a href="#" onclick="return ShowInsertForm();">Add New Record</a>
                        </CommandItemTemplate>

  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Mar 2010 Link to this post

    Hi,

    Here is the code that I tried for same scenario.

    ASPX:

        <CommandItemTemplate>  
            <href="#" onclick="return ShowInsertForm();">Add New Record</a>  
            <href="#" onclick="return ShowEditForm();">Edit Selected</a>  
        </CommandItemTemplate> 

    JavaScript:

            function ShowEditForm() {  
                var grid = $find("<%= RadGrid1.ClientID %>");  
                var masterTableView = grid.get_masterTableView();  
                // var row = masterTableView.get_selectedItems()[0];  
                var id = masterTableView.get_selectedItems()[0].getDataKeyValue('CustomerID');  
                window.radopen("Window.aspx?CustomerID=" + id, "UserListDialog");  
            } 

    Hope this help :)

    Shinu.

  6. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 08 Mar 2010 Link to this post

    Thanks Shinu,

    There is One problem; if users do not select any row and just click the href column in CommandItemTemplate of RadGrid, attached exception error occurs.

    Is there anyway to prevent  this from happening (i.e. do not allow open the RadWindow if no rows has been selected or there are no rows in RadGrid to Display).

    Below is my Command Item Template/MasterTableView Declaration and Window Open Function:

    Thanks again for all your help.

    gc_0620

     

    function ShowEditForm()   
    {  
                    var grid = $find("<%= RadGrid1.ClientID %>");  
                    var masterTableView = grid.get_masterTableView();  
     
                    var id = masterTableView.get_selectedItems()[0].getDataKeyValue('PersonTableID');  
     
                    var owind = radopen("WindowDetailOpen.aspx?PersonTableID=" + id, "UserListDialog");  
                    owind.center();  
                    owind.Maximize();  
                    return false;  
     
                }  
     
     
       <MasterTableView DataKeyNames="PersonTableID"  ClientDataKeyNames="PersonTableID" 
    Name="Master" Font-Size="11px" DataSourceID="SqlDataSource3" 
                        AllowFilteringByColumn="true" CommandItemDisplay="TopAndBottom"
     
     <CommandItemTemplate> 
          <div style="padding: 5px 5px;">  
           Custom command item template for Grid&nbsp;&nbsp;&nbsp;&nbsp;  
           ''''  
           ''''  
           ''''  
     <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Refresh.gif" /> Refresh list</asp:LinkButton>&nbsp;&nbsp;  
     
          <href="#" onclick="return ShowEditForm();" visible='<%# RadGrid1.EditIndexes.Count == 0 %>'>  
           <img style="border: 0px; vertical-align: middle;" alt="" src="Images/Edit.gif" /> 
            Show Edit Form</a> 
     
           </div> 
    </CommandItemTemplate> 
     
     

     

     

  7. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 10 Mar 2010 Link to this post

    Hi gc_0620,

    You could use a simple check if masterTableView.get_selectedItems()[0] is null and to open the radwindow only if it isn't.


    Kind regards,
    Georgi Tunev
    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.
  8. Mandy
    Mandy avatar
    33 posts
    Member since:
    Mar 2010

    Posted 10 Aug 2010 Link to this post

    Hi All

    There is One problem; if users do not select any row and just click the href column in CommandItemTemplate of RadGrid, The Parent mastertable id is always shoing an error .

    What i want is if user justclick on the details table itemcommand item it retrieve the Parent master table datakey so that i can add the child item with that datakey ID.

    Please get me Out of that Problem ASAP..

    Thanks in Advance..
  9. Carina
    Carina avatar
    41 posts
    Member since:
    Nov 2012

    Posted 25 Jan 2013 Link to this post

    Hi, I tried this, but as I ws debugign I noticed the ShowInsertForm and ShowEditForm were not reading the radwindows in the radwindow manager. So it is not getting the properties I set. How can I fix that?
  10. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 28 Jan 2013 Link to this post

    Hi Carina,

    Such a problem may occur if you have more than one RadWindowManager on the page, so the wrong one is used. This help article treats this case, shows how to confirm if this is indeed the problem and offers a solution. I hope it will help you.


    All the best,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017