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

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

8 Answers 634 Views
Window
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 04 Mar 2010, 11:01 PM
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> 
 

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Mar 2010, 08:54 AM
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.
0
gc_0620
Top achievements
Rank 1
answered on 05 Mar 2010, 06:16 PM
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>

0
Shinu
Top achievements
Rank 2
answered on 08 Mar 2010, 12:10 PM

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.

0
gc_0620
Top achievements
Rank 1
answered on 08 Mar 2010, 05:28 PM

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> 
 
 

 

 

0
Georgi Tunev
Telerik team
answered on 10 Mar 2010, 09:34 AM
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.
0
Mandy
Top achievements
Rank 2
answered on 10 Aug 2010, 03:17 PM
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..
0
Carina
Top achievements
Rank 1
answered on 25 Jan 2013, 06:44 PM
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?
0
Marin Bratanov
Telerik team
answered on 28 Jan 2013, 12:26 PM
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.
Tags
Window
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Georgi Tunev
Telerik team
Mandy
Top achievements
Rank 2
Carina
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or