详细视图错误:在命令字段中删除符合条件时 [英] Detail View Error: on delete conformation in command field

查看:78
本文介绍了详细视图错误:在命令字段中删除符合条件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些代码,提示用户在详细信息视图中进行删除确认.我正在使用命令字段(编辑",删除")执行编辑"和删除"功能.

I wrote some code which prompt the user for conformation on delete in a detail view. and I am using command field (Edit, Delete) to perform Edit and delete function.

protected void DViewComputer_DataBound(object sender, EventArgs e)
{
    Button button = (Button)(DViewComputer.Rows[30].Cells[0].Controls[2]);


                    // Add delete confirmation
    ((System.Web.UI.WebControls.Button)(button)).OnClientClick = "if (!confirm('Are you sure " +"you want to delete this record?')) return;";

}



该代码可以正常工作.它要求进行确认并删除记录,但是会引起错误,提示索引超出范围.必须为非负数并且小于集合的大小".这是为什么?我该如何解决?



The code works fine as it was intended to do. It ask for conformation and delete the record, but it causes an error saying "Index was out of range. Must be non-negative and less than the size of the collection". Why is that? how can I fix it?

推荐答案

看一下代码:假设您至少有31行,至少一个单元格,您已经对某些按钮的访问进行了硬编码在#20行中,该行至少具有一个控件,并且该控件与Button分配兼容.哇!您怎么能保证呢?难怪你有这个例外.只是从来没有做过.

—SA
Look at the code: you have hard-coded the access to some button assuming you have at least 31 rows, at least one cell in a row #20, which has at least one control, and also that this control is assignment-compatible with Button. Wow! How could you guarantee that? No wonder you have this exception. Just never ever do it.

—SA


这篇关于详细视图错误:在命令字段中删除符合条件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆