指定的参数超出了有效值的范围。 [英] Specified argument was out of the range of valid values.

查看:58
本文介绍了指定的参数超出了有效值的范围。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加图片onrowdatabound



我尝试过:



I tried adding image onrowdatabound

What I have tried:

string imgAsc = @" <img src='../Images\asc.png' title='Ascending' />";
string imgDes = @" <img src='../Images\des.png' title='Descendng' />";

if (e.Row.RowType == DataControlRowType.Header)
{
    foreach (TableCell cell in e.Row.Cells)
    {
        LinkButton lbSort = (LinkButton)cell.Controls[0];
        if (lbSort.Text == GridView1.SortExpression)
        {
            if (GridView1.SortDirection == SortDirection.Ascending)
                lbSort.Text += imgAsc;
            else
                lbSort.Text += imgDes;
        }
    }
}

推荐答案

错误消息告诉你零控件

检查控件的计数 在假设存在 Controls [0] 之前。



[更新]

使用调试器确切地查看问题的位置以及变量包含的问题。



调试器允许您逐行执行,检查变量和你会看到有一点让它停止你所期望的。

调试器 - 维基百科,免费百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]





调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

当代码没有不做预期的事情,你接近一个错误。
The error message tells you that there is zero Controls.
Check the Count of Controls before assuming that Controls[0] exist.

[Update]
Use the debugger to see exactly where is the problem and the variables contain at the problem.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]


The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.


这篇关于指定的参数超出了有效值的范围。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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