I have 2 GridButtonColumns mapped to distinct Items.. a hyperlink Activate/De-Activate and and the 2nd item contains an imageButton for Delte both of which map to CommandName="Delete". In the OnDeleteCommand handler for the grid in the code behind how do I distinguish the GridEditableItem ImageButton with uniqueName="Delete" from trhe hyperlink with UniqueName="De-Activate" ? I have tried retrieving sender.Gettype.Name and some other ways but do not see a straightforward way to tell which control sent the Delete Command in the handler. Please provide some insight at the earliest. Version used is 2010.35... etc.
<
telerik:GridButtonColumn
CommandName
=
"Delete"
HeaderText
=
""
UniqueName
=
"De-Activate"
HeaderStyle-Width
=
"80px"
ConfirmDialogType
=
"Classic"
>
</
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
HeaderText
=
"Delete"
ButtonType
=
"ImageButton"
UniqueName
=
"Delete"
Text
=
"Delete"
HeaderStyle-Width
=
"80px"
ConfirmDialogType
=
"Classic"
>
</
telerik:GridButtonColumn
>
6 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 22 Oct 2013, 10:42 AM
Hi Prabal,
In order to identify which button click,you can use the CommandArgument for the buttons.
ASPX:
C#:
Thanks,
Princy
In order to identify which button click,you can use the CommandArgument for the buttons.
ASPX:
<
telerik:GridButtonColumn
CommandName
=
"Delete"
UniqueName
=
"De-Activate"
CommandArgument
=
"De-Activate"
. . .>
</
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
CommandArgument
=
"Delete"
UniqueName
=
"Delete"
. . . . >
</
telerik:GridButtonColumn
>
C#:
protected
void
DeleteCommand(
object
source, GridCommandEventArgs e)
{
GridEditableItem item = (GridEditableItem)e.Item;
if
(e.CommandArgument ==
"De-Activate"
)
{
//Code
}
else
if
(e.CommandArgument ==
"Delete"
)
{
//Code
}
}
Thanks,
Princy
0
Prabal
Top achievements
Rank 1
answered on 22 Oct 2013, 01:12 PM
Thanks Princy.. I'll let you know if that works out shortly.
0
Prabal
Top achievements
Rank 1
answered on 22 Oct 2013, 04:53 PM
If I don't put a commandargument for De-Activate in the code behind what is the default e.commandargument value when none exist? Do i check for it=null first?
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Oct 2013, 02:43 AM
Hi Prabal,
If you don't set any value for the CommandArgument, by default it's empty.You may check the condition as follows:
C#:
Thanks,
Princy
If you don't set any value for the CommandArgument, by default it's empty.You may check the condition as follows:
C#:
if
(e.CommandArgument ==
""
)
{
//Your Code
}
Thanks,
Princy
0
Prabal
Top achievements
Rank 1
answered on 31 Oct 2013, 05:47 PM
<
telerik:RadGrid
ID
=
"rgConveyanceFilters"
runat
=
"server"
AutoGenerateColumns
=
"false"
AllowSorting
=
"true"
Visible
=
"false"
GridLines
=
"Both"
OnNeedDataSource
=
"rgConveyanceFilters_OnNeedDataSource"
OnItemDataBound
=
"rgConveyanceFilters_OnItemDataBound"
Width
=
"600px"
OnUpdateCommand
=
"rgConveyanceFilters_OnUpdateCommand"
OnInsertCommand
=
"rgConveyanceFilters_OnInsertCommand"
OnDeleteCommand
=
"rgConveyanceFilters_OnDeleteCommand"
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
HeaderText
=
""
UniqueName
=
"De-Activate"
HeaderStyle-Width
=
"80px"
ConfirmDialogType
=
"Classic"
>
</
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
HeaderText
=
"Delete"
ButtonType
=
"ImageButton"
UniqueName
=
"Delete"
CommandArgument
=
"DeleteFilter"
HeaderStyle-Width
=
"80px"
ConfirmDialogType
=
"Classic"
>
</
telerik:GridButtonColumn
>
0
Princy
Top achievements
Rank 2
answered on 01 Nov 2013, 06:03 AM
Hi Prabal,
You can have custom CommandName for the GridButtonColumn, like CommandName="DeActivate" , but it can be obtained only through the OnItemCommand of the RadGrid. To know about commands that invoke the Rebind() implicitly, have a look into this documentation, such commands can be obtained at their respective events. For custom CommandName please do the following:
C#:
Thanks,
Princy
You can have custom CommandName for the GridButtonColumn, like CommandName="DeActivate" , but it can be obtained only through the OnItemCommand of the RadGrid. To know about commands that invoke the Rebind() implicitly, have a look into this documentation, such commands can be obtained at their respective events. For custom CommandName please do the following:
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.CommandName ==
"DeActivate"
)
{
//Code to delete
}
}
Thanks,
Princy