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

Cannot get EditFormItem in ItemCommand event procedure when trigger button has CommandName different the "Update"has

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gad
Top achievements
Rank 1
gad asked on 28 Dec 2014, 04:49 PM
Hello,
I'm still using radgrid for asp.net (2007 edition).
I have many grids with edit form in user controls.
Usually I have on the user control (the edit form) two link buttons with command names "Update" and "Cancel".
I handle the command in an ItemCommand event procedure.
When those links are clicked I get in the event argument an item which is "EditFormItem".
I tried to add a third link with new commandname "Attach".
When the the event procedure is called after clicking the new link, I get an item of type "Item".
Can I use commandname which is not "Update", "Insert", "Cancel" and still get EditFormItem item?
If it's hardwired, what can I do to access the edit form when using a different commandname like "Attach"?

TIA
Gad

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 01 Jan 2015, 08:32 AM
Hi Gad,

I have to say that the version that you are using is rather old and it is not supported anymore.

Generally, with the latest versions, you can use custom command names without any problems and within the OnItemCommand event handler you can cast the item from the event arguments to GridDataItem and use the EditFormItem property:
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView>
        <Columns>
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
        </Columns>
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <telerik:RadButton runat="server" ID="RadButton1" CommandName="TestCommand"></telerik:RadButton>
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i);
    }
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "TestCommand")
    {
        GridEditFormItem editFormItem = (e.Item as GridDataItem).EditFormItem;
    }
}

Hope this helps.


Best Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
gad
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or