Hi,
I want to delete selected item but in a particular way.
So, I created CommandItemTemplate with some Linbutton, especially DeleteButton with custom Command "DeleteSelected".
On my grid I had property to allow client select row:
I use event "ItemCommand" from serverside and it's correctly fired. But in this event, RadGrid.SelectedItems.Count is always 0.
Where am I wrong ?
I want to delete selected item but in a particular way.
So, I created CommandItemTemplate with some Linbutton, especially DeleteButton with custom Command "DeleteSelected".
On my grid I had property to allow client select row:
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</ClientSettings>
I use event "ItemCommand" from serverside and it's correctly fired. But in this event, RadGrid.SelectedItems.Count is always 0.
if (e.CommandName == "DeleteSelected")
{
if (RadGrid.SelectedItems.Count > 0)
{
//Always 0
}
}
Where am I wrong ?
4 Answers, 1 is accepted
0

Nicolas
Top achievements
Rank 1
answered on 18 Apr 2014, 01:53 PM
Just found the solution: I replaced my LinqDataSource by using event NeedDatasource from RadGrid.
Now it's working. But the question is why ?
Now it's working. But the question is why ?
0

Princy
Top achievements
Rank 2
answered on 22 Apr 2014, 06:56 AM
Hi Nicolas,
I was not able to replicate this behavior at my end. Below is a sample code snippet that I tried, how does it differ from yours, please provide your full code snippet for further help.
ASPX:
C#:
Thanks,
Princy
I was not able to replicate this behavior at my end. Below is a sample code snippet that I tried, how does it differ from yours, please provide your full code snippet for further help.
ASPX:
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"LinqDataSource1"
AllowPaging
=
"true"
AllowMultiRowSelection
=
"true"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
MasterTableView
DataKeyNames
=
"OrderID"
CommandItemDisplay
=
"Top"
>
<
CommandItemTemplate
>
<
asp:LinkButton
ID
=
"LinkButton1"
runat
=
"server"
CommandName
=
"DeleteSelected"
>Delete selected</
asp:LinkButton
>
</
CommandItemTemplate
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
<
asp:LinqDataSource
ID
=
"LinqDataSource1"
runat
=
"server"
ContextTypeName
=
"OrdersDataContext"
EntityTypeName
=
""
Select
=
"new (OrderID, CustomerID, ShipName, ShipCity)"
TableName
=
"Orders"
>
</
asp:LinqDataSource
>
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.CommandName ==
"DeleteSelected"
)
{
if
(RadGrid1.SelectedItems.Count > 0)
{
//Code to delete
}
}
}
Thanks,
Princy
0

Nicolas
Top achievements
Rank 1
answered on 28 Apr 2014, 06:57 AM
Hi Princy,
Sorry for the delay.
I use the event "Selecting" of LinqDataSource and give list to e.Result like this:
Sorry for the delay.
I use the event "Selecting" of LinqDataSource and give list to e.Result like this:
public
void
OnSelecting(
object
sender, LinqDataSourceSelectEventArgs e)
{
List<Foo> datas =
new
List<Foo>();
//Code to get objects
e.Result = datas;
}
0
Hello,
I'm attaching a sample working page showing the correct number of selected item's in the ItemCommand event of the grid when using the OnSelecting event of the LinqDataSource control.
You can check the configuration there and see if there's anything different in your case.
Regards,
Marin
Telerik
I'm attaching a sample working page showing the correct number of selected item's in the ItemCommand event of the grid when using the OnSelecting event of the LinqDataSource control.
You can check the configuration there and see if there's anything different in your case.
Regards,
Marin
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.