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

[Solved] how can I call the same popup window from a different link button other than the GridEditCommandColumn?

4 Answers 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Neeraj asked on 22 Apr 2009, 08:24 PM
how can I call the same popup window from a different link button other than the GridEditCommandColumn?

I have to create a copy functionality in the radGrid. So If have  one more linkbutton with 'copy' text and call the same window as an edit and pass an extra parameter (commandname = 'copy') then I can insercept this and send it to the database as a copy item.

Can someone please provide me an example ?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Apr 2009, 08:10 AM
Hi Neeraj,

Add a GridTemplateColumn to grid column collection and add HyperLink as template. Adding the onclick event to these Hyperlink will allow you to open same RadWindow which is used for editing. Also you can pass the commandName as parameter. See the example which I tried.
ASPX:
 
<telerik:GridTemplateColumn UniqueName="Copy" HeaderText="Copy"
    <ItemTemplate> 
        <asp:HyperLink ID="CopyLink" runat="server" Text="Copy"></asp:HyperLink> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 
<telerik:GridTemplateColumn UniqueName="Edit" HeaderText="Edit"
    <ItemTemplate> 
        <asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

CS:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink"); 
        editLink.Attributes["href"] = "#"
        editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}','{2}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CategoryID"], e.Item.ItemIndex, "Edit"); 
 
        HyperLink copyLink = (HyperLink)e.Item.FindControl("CopyLink"); 
        copyLink.Attributes["href"] = "#"
        copyLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}','{2}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CategoryID"], e.Item.ItemIndex, "Copy"); 
    } 

JavaScript:
 
<script type="text/javascript"
function ShowEditForm(id, rowIndex, commandname) 
    var grid = $find("<%= RadGrid1.ClientID %>");     
    var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element(); 
    grid.get_masterTableView().selectItem(rowControl, true);             
    window.radopen("EditFormCS.aspx?EmployeeID=" + id + "&Command=" + commandname , "UserListDialog"); 
    return false
</script> 

You can also refer the online demo for more details:
Grid / Window Editing

Thanks,
Shinu.
0
Neeraj
Top achievements
Rank 1
answered on 23 Apr 2009, 03:20 PM
Shinu,

Thanks. But now I need to create a new form. I am leveraging the exisiting popup that radGrid and Telerik gives. How can I call this popup that is already predefined ?

<

EditFormSettings CaptionFormatString="Invoice Line Information" >

 

 

<PopUpSettings Modal="true" />

 

 

</EditFormSettings>

 

 

 
0
Neeraj
Top achievements
Rank 1
answered on 23 Apr 2009, 04:13 PM
I was able to get it to work. I used the editItem function. I have a different problem now.  Is there any way that I can set the parameter of the 'update' text box of the popup. When I do the actual update I need to change the stored procedure depending on the parameter ? or can I have a hidden value in the row and set the parameter of this value and then retrieve it to see if it were a copy or a edit ?


function

ShowEditForm(id, rowIndex, commandname)

 

{

 

var grid = $find("<%= gridInvLines.ClientID %>");

 

 

var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();

 

grid.get_masterTableView().selectItem(rowControl,

true);

 

 

//sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());

 

grid.get_masterTableView().editItem(rowControl);

 

//window.radopen("EditFormCS.aspx?EmployeeID=" + id + "&Command=" + commandname , "UserListDialog");

 

 

 

return false;

 

 

}

 

0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2009, 06:10 AM
Hi Neeraj,

From the above given code I suppose you are trying to access the TextBox control in the edit mode on the client side. Here is a code library submission which explains how to access template controls in edit mode on the client side.
Accessing server controls in a grid template on the client

    In the above given code library they are using a  global registry (an array really) that stores the control ID of the control in edit mode and emit script. You can pass the index of the row in edit mode to the client side and then loop through all registered elements and get the one that matches current row index.

You can also have look at the following code library submisson.
Retrieving grid editor value client side

Regards
Shinu.
Tags
Grid
Asked by
Neeraj
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Neeraj
Top achievements
Rank 1
Share this question
or