我有一个表单,我必须将表单值发布到我的动作类.在这种形式中,我有一个需要只读的复选框.我尝试过设置,disabled="true"但在发布到动作类时不起作用.
所以请指教?
我的程序中有以下代码,它在行yearList.SetValue(years [count],count)中抛出索引超出绑定的异常;
protected void invoiceYear_DataBound(object sender, EventArgs e)
{
//invoiceYear.SelectedItem.Value= GetYearRange();
String[] years = GetYearRange().Split(new char[] { '[', ',', ']',' ' });
ListItem [] yearList = new ListItem[]{};
System.Diagnostics.Debug.WriteLine("years-->" + years.Length);
for (int i = 0; i < years.Length; i++)
{
System.Diagnostics.Debug.WriteLine("years-->" + years.GetValue(i));
}
int count = 0;
foreach (String str in years)
{
if (string.IsNullOrEmpty(str))
System.Diagnostics.Debug.WriteLine("empty");
else
{
yearList.SetValue(years[count], count);
count++;
}
}
//System.Diagnostics.Debug.WriteLine("yearList-->" + yearList.GetValue(0));
//invoiceYear.Items.AddRange(yearList);
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码应该从来自服务器的字符串生成列表项.代码如下:
foreach (String str in years)
{
if (string.IsNullOrEmpty(str) || str.Equals(" "))
{
System.Diagnostics.Debug.WriteLine("empty");
}
else
{
System.Diagnostics.Debug.WriteLine(str);
yearLi.Value = str;
yearList.Add(yearLi);
count = yearList.Count;
}
System.Diagnostics.Debug.WriteLine("count-->" + count);
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,如果字符串数组"years"有{2011,2012},那么列表应该是2011年和2012年.但它有2012,2012.我无法在此代码中找到错误.请指教.