[英]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
. 我在ObjectDataSource
有一些数据,在将数据绑定到GridView
,我想从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. 我认为您需要在DataObjectClass中编写另一个SelectMethod,该方法获得一个参数,然后使用该参数来过滤条件。 So that just returning with the rows required to display. 这样就只返回显示所需的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.