Item has already been added. Key in dictionary: '0' Key being added: '0' gridview

Last post 12-18-2008 12:04 PM by bullpit. 1 replies.

Sort Posts:

  • Item has already been added. Key in dictionary: '0' Key being added: '0' gridview

    12-18-2008, 9:28 AM
    • Contributor
      2,317 point Contributor
    • nisarkhan
    • Member since 10-31-2005, 5:55 PM
    • Planet Earth
    • Posts 1,361


    i'm trying to add a key and value to the hashtable and then put that hashtable in Session and this works fine but i'm getting error when i try to browse to different pages in gridview and here is the error message:

    Item has already been added. Key in dictionary: '0'  Key being added: '0' gridview

    here is my code:

    Hashtable ht = new Hashtable();  //declare in class level variable

     protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
     {
            ............
            ........

            ht.Add(e.Row.RowIndex, _sParameters); //error here
            //Session.Add("alertmessages", ht);
            Session["alerts"] = ht;
    }

    how should i deal with it?

    thanks.

    Its all about coding!
    --------------------------
    Don't forget to click "Mark as Answer" on the post(s) that helped you.
  • Re: Item has already been added. Key in dictionary: '0' Key being added: '0' gridview

    12-18-2008, 12:04 PM
    Answer
    • All-Star
      20,949 point All-Star
    • bullpit
    • Member since 06-29-2006, 11:59 AM
    • Posts 4,631

     

    Hashtable ht = new Hashtable();
    
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if(!ht.Contains(e.Row.RowIndex))
       { 
          ht.Add(e.Row.RowIndex, _sParameters); //no error here 
       }
      //Session.Add("alertmessages", ht); Session["alerts"] = ht; 
    }
     
Page 1 of 1 (2 items)