How to get Session value which contains Dictionary Object value in c# .net
<p>I am having drop down in grid view.And that grid view is having pagination.I want the drop down values to persist during pagination.So i used the below code to assign the row index and drop down selected value in Dictionary object and i assigned that to a view state.</p>

<pre><code>Dictionary&lt;int, string&gt; ddlValues = new Dictionary&lt;int, string&gt;();
            for (int rowIndex = 0; rowIndex &lt; GridView1.Rows.Count; rowIndex++)
            {
                DropDownList ddl = GridView1.Rows[rowIndex].FindControl("ddl") as DropDownList;
                if (ddl != null)
                {
                    if (ddl.SelectedIndex &gt; 0) //.. or sensible check appropriate to you
                    {
                        int ddlIndex = rowIndex * e.NewPageIndex + 1;
                        //.. add pageIndex and selectedValue to dictionary      
                        ddlValues.Add(ddlIndex, ddl.SelectedValue);
                    }
                }
            }
            ViewState["ddlvalue"] = ddlValues;
</code></pre>

<p>in page load i want to get the selected value and assign to grid view drop down.so i am doing the following:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
   {
    if (!IsPostBack)
     {
       // some code follows here
     }
    else
       {
         if (Convert.ToString(ViewState["ddlvalue"]) != null &amp;&amp; Convert.ToString(ViewState["ddlvalue"]) != "")
                    {
                        for (int i = 0; i &lt; GridView1.Rows.Count; i++)
                        {
                            DropDownList drpcmpny = (DropDownList)GridView1.Rows[i].FindControl("ddl");
                            Dictionary&lt;int, string&gt; ddlValues = (Dictionary&lt;int, string&gt;)ViewState["ddlvalue"];
                         //   -------&gt;    Here i am not able to get the collection //individual items.
drpcmpny.SelectedValue = ddlValues.Values.ToString();

                        }
                    }
                }
}
</code></pre>

<p>SO, I am not able to assign the generic collection to the drop down selected value.so i want to know how to retrieve the value and key individually from the viewstate
Please Help</p>
