我有这样的代码
protected void rptCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRow dr = ((DataRowView)e.Item.DataItem).Row;
LinkButton lnkcoursename = (LinkButton)e.Item.FindControl("lnkCategory");
Label lblcount = (Label)e.Item.FindControl("lblCount");
string k = lnkcoursename.CommandArgument.ToString();
if (k != "0")
{
TrainingCourse traningCourse = new TrainingCourse();
int count = traningCourse.CourseCount(Convert.ToInt32(k), "", "");
if (count == 0)
{
//This code is not working
dr.Delete();
dr.AcceptChanges();
}
else
{
lblcount.Text = "(" + count + ")";
}
}
}
现在我的问题是,如果我发现count = 0,那么我想从转发器中删除该行。我不想从数据库中删除它然后重新绑定它......
答案 0 :(得分:11)
您尝试删除与数据源关联的行。 但是对于这项任务来说,隐藏项目要好得多:
e.Item.Visible = false