当我不检查复选框。 [英] When I am not Checking check box.

查看:77
本文介绍了当我不检查复选框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,

我对checkboxlist有疑问。我面临错误长度不能小于零。参数名称:长度。我的代码是

Hello sir,
I have aproblem with checkboxlist.I am facing the error " Length cannot be less than zero. Parameter name: length ".My code is

string chkIncludeWithsalary = "";
            foreach (ListItem lst in chkIncludedWithSalary.Items)
            {
                if (lst.Selected)
                    chkIncludeWithsalary += lst.Text + ",";
            }

            chkIncludeWithsalary = chkIncludeWithsalary.Substring(0, (chkIncludeWithsalary.Length - 1));



如果我没有检查任何ckeckbox。


If i am not checking any ckeckbox.

推荐答案

嗨。 。



我看到很多相同的问题..所有要做的就是你必须正确加载你的复选框。错误长度不能小于零本身表示您的复选框列表长度为零。意味着你的复选框列表中没有行或项目。所以绑定你的复选框列表就可以对它进行任何操作。



你可以绑定
Hi..

I saw the same problem form many.. All is to do is you must load your checkboxlist properly.. Error "Length cannot be less than zero" itself indicating that your checkbox list length is zero. Means there are no rows or item in your checkboxlist.. So bind your checkboxlist befor doing any operations on it.

you can bind on
PreRenderComplete()

Page_Load()

Page_Init()





以上说明适用于下拉列表,复选框列表,单选按钮列表等。



Above said is applicable for dropdownlist, checkboxlist, radiobutton lists etc..


错误必须在这里:

Error must be here:
chkIncludeWithsalary.Substring(0, (chkIncludeWithsalary.Length - 1));



子串参数为:startPosition,NoOfCharacters - 两者都必须为0或者以上,不能为负数。



根据错误和我看到的代码,看起来第二个参数是负值,因此错误。

(chkIncludeWithsalary.Length - 1) - >是负数,这意味着 chkIncludeWithsalary 中没有值 - 它是空的。



你需要制作确保字符串中有一些东西 chkIncludeWithsalary 。根据代码,只要复选框列表中没有选择,您就会收到此错误。处理它。


Substring parameters are: startPosition, NoOfCharacters - both has to be 0 or above, cannot be negative.

Based on error and the code I see, it looks like second parameter is a negative value and hence the error.
(chkIncludeWithsalary.Length - 1) -> is negative, which means that there was no value in chkIncludeWithsalary - it was empty.

You need to make sure that there is something in the string chkIncludeWithsalary . Based on the code, you will get this error whenever there is no selection in the checkboxlist. Handle it.


这篇关于当我不检查复选框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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