简体   繁体   中英

Delete row from objectdatasource before binding to gridview

I have some data in ObjectDataSource , before binding the data to the GridView , I want to remove some rows from the DataSource .

This is what I am trying:

protected void gvExitInterview_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            User employee = (User) e.Row.DataItem;

            if(//some condition here)
            {
                //do nothing
            }
            else
            {
                //delete the row
                this.gv.DeleteRow(e.Row.RowIndex);
                return;
            }
}
}

These are my deletion methods:

protected void gvExitInterview_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }


    protected void gvExitInterview_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        gv.DataBind();
    }

This is my grid binding:

private void BuildGrid(DateTime from, DateTime to)
    {
        this.objDS.TypeName = "EmployeeManagement";
        this.objDS.SelectMethod = "GetEmployees";
        this.objDS.SelectCountMethod = "GetEmployeesCount";
        this.objDS.SelectParameters.Clear();
        this.objDS.SelectParameters.Add("from", from.ToString());
        this.objDS.SelectParameters.Add("to", to.ToString());
        this.objDS.SelectParameters.Add("csvEntities", csv);
        this.objDS.SelectParameters.Add("sortExpression", ViewState["SortColumn"].ToString());
        this.gv.DataSource = objDS;
        this.gv.DataBind();
    }

This is not working, it does not filter or delete any data from the grid. Any idea how to do explicit deletion?

I think you need to write another SelectMethod in the DataObjectClass which get a parameter which you use pass to filter condition. So that just returning with the rows required to display.

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