protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int index = Convert.ToInt32(e.CommandArgument);
        string fcode = this.GridView1.DataKeys[index].Value.ToString();   
        if (e.CommandName != "AddtoBus")
        {
            if (Session["bus"] == null)
            {
                System.Collections.Hashtable ht = new Hashtable();
                ht.Add(fcode, 1);
                Session["bus"] = ht;
            }
            else
            {
                System.Collections.Hashtable ht = (Hashtable)Session["bus"];
                if (ht[fcode] == null)
                {
                    ht[fcode] = 1;
                }
                else
                {
                    ht[fcode] = (int)ht[fcode] + 1;
                }
                Session["bus"] = ht;
            }
        }
    }这是添加段的代码?哪位高手点一下....

解决方案 »

  1.   

    //Label label1 = (Label)dl.FindControl("fcode")说说你这句想干什么,从Label里取值(你贴的代码里未见有此控件)?从session里取值?
    报错的提示...
      

  2.   

    Label label1 = (Label)(dl.FindControl("fcode"));//找到装载哈希表key字段的那个控件 我感觉这句不怎么对啊....我窗体里没有这个FCODE的穿体
      

  3.   

    foreach (DataListItem dl in this.DataList1.Items)//遍历集合
            {              
                 TextBox tb=(TextBox)dl.FindControl("TextBox1");//找到文本框 
                 int newfcode=Convert.ToInt32(tb.Text.ToString());//查出文本框里面的值 
                 Hashtable ht=(Hashtable)Session["bus"];//把session["bus"]对象赋值给哈希表 ht  
                 string fcode = this.DataList1.DataKeys[DataList1.SelectedIndex].ToString(); 
                 int oldpid=(int)ht[fcode];//求得原来的数量         
                 if (newfcode != oldpid)//如果文本框里的值不等于原来的数量,就用新的更换到哈希表中的值 
                   {
                       ht[fcode] = newfcode; 
                   } 
                 Session["bus"]=ht;//最后再更新Session 对象 */
            } 这样改可以么?!
      

  4.   

    foreach (DataListItem dl in this.DataList1.Items)//遍历集合
            {              
                 TextBox tb=(TextBox)dl.FindControl("TextBox1");/ 到文本框 
                 int newfcode=Convert.ToInt32(tb.Text.ToString());//查出文本框里面的值 
                 Hashtable ht=(Hashtable)Session["bus"];//把session["bus"]对象赋值给哈希表 ht  
                 string fcode = DataList1.Items[0].ItemIndex.ToString();
                 int oldpid=(int)ht[fcode];//求得原来的数量         
                 if (newfcode != oldpid)//如果文本框里的值不等于原来的数量,就用新的更换到哈希表中的值 
                   {
                       ht[fcode] = newfcode; 
                   } 
                 Session["bus"]=ht;//最后再更新Session 对象 */
            } 我重新改了改还是不行阿?!