Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1740
How to delete the grid row on a button click
posted

Using NetAdvantage Select 2010 Vol. 2 – Webdatagrid for a project and having following issue:

Each grid row has ‘Delete’ image button. On button click, need to remove that row (single select) and refresh the grid with the update. Used following code, but it doesn’t work:

 

--Delete Button

<ig:TemplateDataField Key="Delete" Width="20px" >

            <ItemTemplate>

              <asp:ImageButton ID="imgDelete"  CausesValidation="false" CommandArgument="args" CommandName="D"

                 ImageUrl="~/Images/Cancel.gif" runat="server" />

               </ItemTemplate>

</ig:TemplateDataField>

 

--code behind

protected void wdgComment_ItemCommand(object sender, Infragistics.Web.UI.GridControls.HandleCommandEventArgs e)

        {

            foreach (GridRecord item in wdgComment.Behaviors.Selection.SelectedRows)

            {

                if (item != null)

                {

                    wdgComment.Behaviors.Selection.SelectedRows.Remove(item);

                }

            }

 

            e.Handled = true;

        }

 

protected void Page_Load(object sender, EventArgs e)

        {

            wdgComment.ItemCommand += new ItemCommandEventHandler(wdgComment_ItemCommand);

 

            wdgComment.DataSource = GetDataSource();

            wdgComment.DataKeyFields = "Comment_Id";

            

            if (!Page.IsPostBack)

            {

                wdgComment.DataBind();

            }

 

        }

Parents
No Data
Reply
  • 33839
    Suggested Answer
    posted

    Hi tkthatikonda,

    You are never actually removing the row from the DataSource.  The following line,

    wdgComment.Behaviors.Selection.SelectedRows.Remove(item);

    just unselects the row.  If you do this on the server, you will need to add the code to remove it from your datasource.  Another option would be to handle a client click of your image button and remove the row on the client.  It would be removed via an ajax callback.  You would need to add the editing core behavior.

     

    regards,

    David Young

Children
No Data