本帖最后由 cde32 于 2012-10-04 17:28:59 编辑

解决方案 »

  1.   

    那当然了,如果不够10个字符的话,你截取10个字符,肯定是超过索引了,你需要利用三元运算符做下判断<%=(Request.Form["a2"].ToString().Length<10?Request.Form["a2"].ToString():Request.Form["a2"].ToString().Substring(0,10))%>
      

  2.   

    索引越界,如果索引小于10是肯定会报错的
    <%= Request.Form["a2"].ToString().Length >=10 ?Request.Form["a2"].Substring(0,10):
    Request.Form["a2"].Substring(0,Request.Form["a2"].ToString().Length)
    %>不知道这个地方可不可以嵌入三元表达式,自己尝试下吧!
      

  3.   

    如果在<%%>中的表达式代码过于复杂或冗长,还是建议所求值过程放到cs中去写。前台只需调cs中的方法就可以了前台:<%=GetA2Value() %>
    后台cs中: public String GetA2Value()
            {            string v2 = Request.Form["a2"];            if (v2.Length > 10)
                {
                    return v2.Substring(0, 10);
                }
                else
                {
                    return v2;
                }
            }
      

  4.   

    出错了:Index and length must refer to a location within the string.
    Parameter name: length 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
    Parameter name: length再测试一下二楼结果……