GRIDVIEW IS HIDING AFTER ROW DELETING EVENT

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
C# 
C#
 1075  View(s)
Ratings:
Rate this:

I am using GridView Row command Event for deleting row from Gridview, I have added RowDeleting Event of gridview, but after deleting the GridView is getting hide. Below is my code

 protected void Page_Load(object sender, EventArgs e)

        {

       if (!Page.IsPostBack){

LoadData()//Here I am databinding the Grid

}

}

private void LoadData()

{

var data=MyClass.GetRecords();//it returns  DataTable

dg.DataSource=data;

dg.DataBind();

}

protected void dg_RowCommand(Object sender, GridViewCommandEventArgs e)

{

    if(e.CommandName =="del")

    {

        //Delete Records

        dg.DataBind();

    }

}

public void dg_RowDeleting(Object sender, GridViewDeleteEventArgs e)

{

    dg.DataBind();

}

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: GridView is hiding after Row Deleting Event

    Hi Mark,


    My guess is you are missing DataSource after deleting the rows.

    Try this

    protected void dg_RowCommand(Object sender, GridViewCommandEventArgs e)

    {

        if(e.CommandName =="del")

        {

            //Delete Records

           LoadData();

        }

    }

    public void dg_RowDeleting(Object sender, GridViewDeleteEventArgs e)

    {

        LoadData();

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!