首先还是头一看见委托竟然可以在方法中做参数使用,然后就是ApplyActionToCheckedFeedback中传入的是FeedbackItem不是FeedbackAction。最奇怪的也就是FeedbackItem.Delete方法,在后面action(feedbackItem)这行代码这里被执行了;FeedbackItem.Delete的完整定义是public static void Delete(FeedbackItem feedback)。Delete为什么在action(feedbackItem)后会运行,委托?这么委托真的是不明白,从没见过。 protected void OnDeleteClick(object sender, System.EventArgs e)
{
if (ApplyActionToCheckedFeedback(FeedbackItem.Delete) == 0)
{
Messages.ShowMessage("Nothing was selected to be deleted.", true);
return;
}
BindList();
}
private int ApplyActionToCheckedFeedback(FeedbackAction action)
{
int actionsApplied = 0;
foreach(RepeaterItem item in this.rprSelectionList.Items)
{
// Get the checkbox from the item or the alternating item.
CheckBox deleteCheck = item.FindControl("chkDelete") as CheckBox;
if(deleteCheck == null)
{
deleteCheck = item.FindControl("chkDeleteAlt") as CheckBox;
} if(deleteCheck != null && deleteCheck.Checked)
{
// Get the FeedbackId from the item or the alternating item.
HtmlInputHidden feedbackId = item.FindControl("FeedbackId") as HtmlInputHidden;
if(feedbackId == null)
{
feedbackId = item.FindControl("FeedbackIdAlt") as HtmlInputHidden;
} int id;
if(int.TryParse(feedbackId.Value, out id))
{
FeedbackItem feedbackItem = FeedbackItem.Get(id);
if (feedbackItem != null)
{
actionsApplied++;
action(feedbackItem);
}
}
}
}
return actionsApplied;
} delegate void FeedbackAction(FeedbackItem feedback);
{
if (ApplyActionToCheckedFeedback(FeedbackItem.Delete) == 0)
{
Messages.ShowMessage("Nothing was selected to be deleted.", true);
return;
}
BindList();
}
private int ApplyActionToCheckedFeedback(FeedbackAction action)
{
int actionsApplied = 0;
foreach(RepeaterItem item in this.rprSelectionList.Items)
{
// Get the checkbox from the item or the alternating item.
CheckBox deleteCheck = item.FindControl("chkDelete") as CheckBox;
if(deleteCheck == null)
{
deleteCheck = item.FindControl("chkDeleteAlt") as CheckBox;
} if(deleteCheck != null && deleteCheck.Checked)
{
// Get the FeedbackId from the item or the alternating item.
HtmlInputHidden feedbackId = item.FindControl("FeedbackId") as HtmlInputHidden;
if(feedbackId == null)
{
feedbackId = item.FindControl("FeedbackIdAlt") as HtmlInputHidden;
} int id;
if(int.TryParse(feedbackId.Value, out id))
{
FeedbackItem feedbackItem = FeedbackItem.Get(id);
if (feedbackItem != null)
{
actionsApplied++;
action(feedbackItem);
}
}
}
}
return actionsApplied;
} delegate void FeedbackAction(FeedbackItem feedback);
解决方案 »
- 有关TreeView生成的动态菜单怎么建立连接在指定的框架里显示的问题!!!!
- 反射 web.config
- 小弟想买本书实战的书,请高手推荐一下!
- 访问网站时正常,但是上传文件时弹出登陆框要求登陆。如何解决这个问题(已经设为匿名访问)
- vs2005怎么用向导添加类成员啊
- 【源码发布,不可用于商业目的】刚刚做的一个项目管理的软件完成了50%,有兴趣的朋友可以拿去研究研究。
- NET给目录添加权限时出现下面的错误
- 一个奇怪的问题:&# 24322 ; 这样的字符串,浏览器直接显示汉字???
- 請問這種類型要怎麼轉換
- 样式表。。。。没有效果?小问题,请大伙帮忙解决啊!
- 今天去面试碰到一条SQL的问题
- 数据库问题
你可以根据不同的用户调用不同的方法,也可以传过去不同顾客等级的委托。