当我不检查复选框

当我不检查复选框

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

问题描述

您好,先生,

我对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.

推荐答案

PreRenderComplete()

Page_Load()

Page_Init()





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



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


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.


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

08-13 13:58