简体   繁体   中英

Confirmation Dialog On Telerik RadGrid

I am trying to add a confirmation dialog in my telerik rad grid but I am having issues. It's causing the eventpagevaldition error to crop up. I have the following RadGrid and when I set it to true its not deleting the row so I don't know what is wrong. Can someone help?

 <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>

Then in my code behind it's the following

 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();

        }


    }

But it's not deleting the row at all - it's staying in memeory. I must add when I click the autogen one it works fine.

Call grdSoccerPlayers.Rebind(); method. This will have the grid request its data from the data source again. The DataBind method has very limited use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM