我正在尝试在我的telerik rad网格中添加一个确认对话框,但我遇到了问题。它导致出现eventpagevaldition错误。我有以下RadGrid,当我将其设置为true时,它不删除行,所以我不知道有什么问题。有人可以帮忙吗?
<telerik:RadGrid ID="grdSoccerPlayers" runat="server" AutoGenerateColumns="False" DataSourceID="entyPlayer" GroupPanelPosition="Top" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" OnItemCommand="grdSoccerPlayers_ItemCommand" CellSpacing="-1" GridLines="Both" AllowAutomaticDeletes="True">
<MasterTableView DataSourceID="entyPlayer" CommandItemDisplay="Top" DataKeyNames="id">
<Columns>
<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="fname" FilterControlAltText="Filter fname column" HeaderText="fname" ReadOnly="True" SortExpression="fname" UniqueName="fname">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="lname" FilterControlAltText="Filter lname column" HeaderText="lname" ReadOnly="True" SortExpression="lname" UniqueName="lname">
</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" FilterControlAltText="Filter createdDate column" HeaderText="createdDate" ReadOnly="True" SortExpression="createdDate" UniqueName="createdDate" DataType="System.DateTime">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="author" FilterControlAltText="Filter author column" HeaderText="author" ReadOnly="True" SortExpression="author" UniqueName="author">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="siteid" FilterControlAltText="Filter siteid column" HeaderText="siteid" ReadOnly="True" SortExpression="siteid" UniqueName="siteid" DataType="System.Guid">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="gender" FilterControlAltText="Filter gender column" HeaderText="gender" ReadOnly="True" SortExpression="gender" UniqueName="gender">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="id" DataType="System.Guid" FilterControlAltText="Filter id column" HeaderText="id" ReadOnly="True" SortExpression="id" UniqueName="id">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete"
ButtonType="ImageButton" ImageUrl="~/Icons/delete.png" AutoPostBackOnFilter="true"
ConfirmTitle="Delete" ConfirmDialogType="Classic"
ConfirmText="Are you sure want to delete the selected report?" />
</Columns>
</MasterTableView>
</telerik:RadGrid><telerik:RadWindow ID="rdConfim" runat="server"></telerik:RadWindow>
然后在我的代码背后是以下
protected void grdSoccerPlayers_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if(e.CommandName == RadGrid.InitInsertCommandName)
{
Guid strId = Guid.Empty;
Response.Redirect("edit.aspx?id=" + strId.ToString());
}
if (e.CommandName == "Edit")
{
GridDataItem item = e.Item as GridDataItem;
Guid strId = new Guid(item.GetDataKeyValue("id").ToString());
Response.Redirect("edit.aspx?id=" + strId.ToString());
}
if (e.CommandName == RadGrid.InitInsertCommandName)
{
Response.Redirect("edit.aspx");
}
if(e.CommandName ==RadGrid.DeleteCommandName)
{
GridDataItem item = e.Item as GridDataItem;
Guid strId = new Guid(item.GetDataKeyValue("id").ToString());
player _player = _dal.GetPlayerBYID(strId);
_dal.SoccerEntities.players.DeleteObject(_player);
_dal.SoccerEntities.SaveChanges();
grdSoccerPlayers.DataBind();
}
}
但它根本没有删除这一行 - 它留在了记忆中。我必须添加,当我点击自动一个它工作正常。
答案 0 :(得分:0)
调用grdSoccerPlayers.Rebind();
方法。这将使网格再次从数据源请求其数据。 DataBind
方法的使用非常有限。