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

How to open usercontrol as editform from commanditemtemplate?

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marliela
Top achievements
Rank 1
Marliela asked on 21 Aug 2012, 10:19 AM
Hi all,

I have a commanditemtemplate with a button that I would like to use to edit one row from the radgrid using a popup usercontrol.

The situation:
I cannot edit the row with the GridEditCommandColumn because there is only one row in the entire grid that is allowed to be edited, and I don't want to work with hiding buttons because I think it's an ugly solution. Therefore I would like to edit the row by pressing a button at the commanditemtemplate.

Unfortunately, the popup doesn't show. I probably forgot some setting somewhere, could someone please help me?

aspx code snippet
<MasterTableView DataKeyNames="keyName" AllowMultiColumnSorting="True" EditMode="PopUp"
    CommandItemDisplay="Top">
        <EditFormSettings EditFormType="WebUserControl" />
            <CommandItemSettings ShowAddNewRecordButton="false" AddNewRecordText=""
                ShowRefreshButton="false" RefreshText="" />
            <CommandItemTemplate>
                <telerik:RadButton ID="RadButtonDone" runat="server" Text="Done"
                    CommandArgument="Done" CommandName="Edit"
                    ToolTip="Mark the item as done">
                    <Icon PrimaryIconUrl="Images/done.gif" PrimaryIconLeft="8"
                        PrimaryIconTop="5" />
                </telerik:RadButton>
            </CommandItemTemplate>

code behind c#:
protected void RadGridMyGrid_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.EditCommandName)
    {
        //  Change status to 'Done'
        if (e.CommandArgument == "Done")
        {
            SessionState.Current.intKey =
               GetKeyValueFromRowThatIsAllowedToBeEdited(ValueFromSessionState);
            e.Item.OwnerTableView.IsItemInserted = false;
            e.Item.OwnerTableView.EditFormSettings.PopUpSettings.Width = 700;
            e.Item.OwnerTableView.EditFormSettings.PopUpSettings.Modal = true;
            e.Item.OwnerTableView.EditFormSettings.UserControlName =
                "ChangeStatusToDone.ascx";
        }
    }
}

Thank you!

Marlies

1 Answer, 1 is accepted

Sort by
0
Marliela
Top achievements
Rank 1
answered on 21 Aug 2012, 02:46 PM
I figured out a work around!

Change the CommandName of the button to "InitInsert"
Change the item command event in the code behind :
add: 
e.Canceled = true;
RadGridMyGrid.EditIndexes.Clear();
   e.Item.OwnerTableView.InsertItem(); 


aspx:
<MasterTableView DataKeyNames="keyName" AllowMultiColumnSorting="True" EditMode="PopUp"
    CommandItemDisplay="Top">
        <EditFormSettings EditFormType="WebUserControl" />
            <CommandItemSettings ShowAddNewRecordButton="false" AddNewRecordText=""
                ShowRefreshButton="false" RefreshText="" />
            <CommandItemTemplate>
                <telerik:RadButton ID="RadButtonDone" runat="server" Text="Done"
                    CommandArgument="Done" CommandName="InitInsert"
                    ToolTip="Mark the item as done">
                    <Icon PrimaryIconUrl="Images/done.gif" PrimaryIconLeft="8"
                        PrimaryIconTop="5" />
                </telerik:RadButton>
            </CommandItemTemplate>

Code behind:
protected void RadGridMyGrid_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        e.Canceled = true;
        RadGridMyGrid.EditIndexes.Clear();
 
        //  Change status to 'Done'
        if (e.CommandArgument == "Done")
        {
            SessionState.Current.intKey =
               GetKeyValueFromRowThatIsAllowedToBeEdited(ValueFromSessionState);
            e.Item.OwnerTableView.IsItemInserted = false;
            e.Item.OwnerTableView.EditFormSettings.PopUpSettings.Width = 700;
            e.Item.OwnerTableView.EditFormSettings.PopUpSettings.Modal = true;
            e.Item.OwnerTableView.EditFormSettings.UserControlName =
                "ChangeStatusToDone.ascx";
            e.Item.OwnerTableView.InsertItem();
        }
    }
}

Tags
Grid
Asked by
Marliela
Top achievements
Rank 1
Answers by
Marliela
Top achievements
Rank 1
Share this question
or