我这个是想做C#生成静态页面+分页的,当他第一次运行的时候不会暴错,但运行到第2次,替换字符的时候显示
已添加项。字典中的关键字:“$first$”所添加的关键字:“$first$” 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentException: 已添加项。字典中的关键字:“$first$”所添加的关键字:“$first$”源错误: 
行 195:                //if (ht.Contains("first")==true)
行 196:                //{
行 197:                    ht.Add("$first$", first);
行 198:                //}
行 199:                //if (ht.Contains("prev") == true)
 请问下这个问题如何解决。

解决方案 »

  1.   

    LZ你是想HashTable中添加了相同的项了吧?那当然会有这样的错误啊
    MSDN上的解释:ArgumentException Hashtable 中已存在具有相同键的元素。
     
      

  2.   

    第二次的时候重新初始化HashTable或者清空HashTable了么?也许还有残存的数据在里面吧
      

  3.   

    这个是什么意思
    不是跟ht.Add("$first$", first);一样的么
      

  4.   

                    //if (ht.Contains("first")==true)
                    //{
                        ht.Add("$first$", first);
                    //}
                    //if (ht.Contains("prev") == true)
                    //{
                        ht.Add("$prev$", prev);
                    //}
                    //if (ht.Contains("next") == true)
                    //{
                        ht.Add("$next$", next);
                    //}
                    //if (ht.Contains("last") == true)
                    //{
                        ht.Add("$last$", last);
                    //}
                    //if (ht.Contains("Left_CassType_Lfet") == true)
                    //{
                        ht.Add("$Left_CassType_Lfet$", Left_CassType1);
                    //}
                    //if (ht.Contains("productlist") == true)
                    //{
                        ht.Add("$productlist$", productlist);
                    //}
                    //if (ht.Contains("newsCount") == true)
                    //{
                        ht.Add("$newsCount$", "<font color='red'>" + cmdSql.ToString() + "</font>");
                    //}
                    //if (ht.Contains("Count") == true)
                    //{
                        ht.Add("$Count$", "<font color='red'>" + y + "/" + Pagesize + "</font>");
                    //}  
                    //ht.Add("$Left_CassType_Lfet$", Left_CassType1);
                    //ht.Add("$productlist$", productlist);
                    //ht.Add("$newsCount$", "<font color='red'>" + cmdSql.ToString() + "</font>");
                    //ht.Add("$Count$", "<font color='red'>" + y + "/" + Pagesize + "</font>");
                    ItemIndex_html = ToIO.Replace(ItemIndex_html, ht);
                    ToIO.Writer("../prohtml_" + dt.Rows[i]["PKID"].ToString() +"_"+y.ToString()+".html", ItemIndex_html);
                    ht.Clear();
                    ItemIndex_html = string.Empty;
                    MessageBox("操作成功!");
    这样过后,第2页的数据跟第一页的一样,郁闷
      

  5.   


    说错了,这样第2页,一点数据都没,这样没调用到html模版页