我正在使用实体框架来填充网格,但我试图删除该项目,但没有错误就是没有任何行动。
我的网格如下离开没有问题是诚实的,因为我正在使用类型播放器,所以它应该删除。
我没有任何进一步的帮助,有人可以请你帮忙。
<telerik:RadGrid ID="grdSoccerPlayers" runat="server" AutoGenerateColumns="False" GroupPanelPosition="Top" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" OnItemCommand="grdSoccerPlayers_ItemCommand" CellSpacing="-1" GridLines="Both" AllowAutomaticDeletes="True">
<MasterTableView CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn DataField="id" DataType="System.Guid" FilterControlAltText="Filter id column" HeaderText="id" ReadOnly="True" SortExpression="id" UniqueName="id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Name" ReadOnly="True" SortExpression="Name" UniqueName="Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="player_id" FilterControlAltText="Filter player_id column" HeaderText="player_id" ReadOnly="True" SortExpression="player_id" UniqueName="player_id">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="gender" FilterControlAltText="Filter gender column" HeaderText="gender" ReadOnly="True" SortExpression="gender" UniqueName="gender">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="town" FilterControlAltText="Filter town column" HeaderText="town" ReadOnly="True" SortExpression="town" UniqueName="town">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="telephone" FilterControlAltText="Filter telephone column" HeaderText="telephone" ReadOnly="True" SortExpression="telephone" UniqueName="telephone">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="email" FilterControlAltText="Filter email column" HeaderText="email" ReadOnly="True" SortExpression="email" UniqueName="email">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="active" DataType="System.Boolean" FilterControlAltText="Filter active column" HeaderText="active" ReadOnly="True" SortExpression="active" UniqueName="active">
</telerik:GridCheckBoxColumn>
<telerik:GridBoundColumn DataField="createdDate" DataType="System.DateTime" FilterControlAltText="Filter createdDate column" HeaderText="createdDate" ReadOnly="True" SortExpression="createdDate" UniqueName="createdDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="author" FilterControlAltText="Filter author column" HeaderText="author" ReadOnly="True" SortExpression="author" UniqueName="author">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="teamId" DataType="System.Guid" FilterControlAltText="Filter teamId column" HeaderText="teamId" ReadOnly="True" SortExpression="teamId" UniqueName="teamId">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="address" FilterControlAltText="Filter address column" HeaderText="address" ReadOnly="True" SortExpression="address" UniqueName="address">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete"
ButtonType="ImageButton" ImageUrl="~/Icons/delete.png" AutoPostBackOnFilter="true" HeaderText="Actions"
ConfirmTitle="Delete" ConfirmDialogType="Classic"
ConfirmText="Are you sure want to delete the selected player?" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
if (e.CommandName == "Delete")
{
GridDataItem item = e.Item as GridDataItem;
Guid strId = new Guid(item.GetDataKeyValue("id").ToString());
player _player = _dal.GetPlayerBYID(strId);
_dal.SoccerEntities.AddToplayers(_player);
_dal.SoccerEntities.DeleteObject(_player);
_dal.SoccerEntities.SaveChanges();
grdSoccerPlayers.DataBind();
grdSoccerPlayers.Rebind();
}
我的数据源是一个linq查询,如下所示
public player GetPlayerBYID(Guid _playerId)
{
try
{
if (_playerId == Guid.Empty)
{
player _player = new player();
_player.player_id = "16-56-232";
return _player;
}
else
{
var q = SoccerEntities.players.Where(p => p.id == _playerId);
if (q == null)
throw new EntityContextException(string.Format("A player could not be found {0}!", _playerId));
else
return q.ToList()[0];
}
}
catch (Exception ex)
{
throw new EntityContextException("GetPlayerBYID failed.", ex);
}
}
答案 0 :(得分:0)
我猜你错过了OnDeleteCommand。查看此控件的文档。 http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/delete-records/overview