see
Adding Design-Time Support to ASP.NET Controls
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNet-AddDesignTimeSupport.asp
>>>allStates[1] = stringarray.ToString();it is probably a bad choice, stringarray.ToString() returns the type of the array, try allStates[1] = stringarray;then (没试,也许不工作) if (myState[1] != null)
          string[,] s =(string[,])myState[1];

解决方案 »

  1.   

    sorry, I was wrong, it appears, you cannot just save [,] array as is, although [][] does work, then you probably have to do some conversion, or you should stay away with [,], but use [][] insteadprotected override void LoadViewState(object savedState) 
        {
          if (savedState != null)
          {
            object[] myState = (object[])savedState;
            if (myState[0] != null)
              base.LoadViewState(myState[0]);
    if (myState.Length > 3)
    {
    stringarray = new string[(int)myState[1], (int)myState[2]];
    for (int i=0; i < stringarray.GetLength(0); i++)
    {
    for (int j=0; j < stringarray.GetLength(1); j++)
    stringarray[i,j] = ((string[])myState[i+3])[j];
    }
    }         //if (myState[1] != null)
             //   stringarray=(string[,])myState[1];        
          }
        }    protected override object SaveViewState()
        { 
          object baseState = base.SaveViewState();
          object[] allStates = new object[3+stringarray.GetLength(0)*stringarray.GetLength(1)];
          allStates[0] = baseState;
     allStates[1] = stringarray.GetLength(0);
    allStates[2] = stringarray.GetLength(1); for (int i=0; i < stringarray.GetLength(0); i++)
    {
    string[] s = new string[stringarray.GetLength(1)];
    for (int j=0; j < stringarray.GetLength(1); j++)
    s[j] = stringarray[i,j];
    allStates[i+3] = s;
    }
          return allStates;
        }
      

  2.   

    1.
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNet-AddDesignTimeSupport.asp
    這個網頁已經打印出來了,19頁,在第7頁找到答案
    2.方法有點麻煩,不知道先把數組轉成Hashtable再用allStates[1] = Hashtable1這個行不行