Advertise with us

GridView is hiding after Row Deleting Event

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

}

Last updated:3/6/2014 11:15:55 PM

1 Answers

Pravesh Singh
Pravesh Singh

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

}

Last updated:3/6/2014 11:15:55 PM

Answer