DropDownValues are changed when i delete a record in GridView
<p>I have a <strong>Gridview</strong> ,in that one of the Column is <strong>DropDownList</strong> .I have 10 Records in my Grid and my DropDown Values are like this 1,2,3....10.
This is the format to store my DropDown values ,if i <strong>delete 4 Row</strong> ,then my DropDown Values are also Changed like <strong>1,2,3,4....9</strong>.This is my task ,but i'm getting like this format <strong>1,2,3,--,5...10</strong>.Any one Can help me to do this .I wrote code like this</p>

<p><strong>This is Remove Button Code:</strong></p>

<pre><code>protected void btnToRemove_OnClick(object sender, EventArgs e)
    {
        EIPEDMS objEDMS = new EIPEDMS();
        string Result = "";

        DataTable dtTo = ViewState["PAM"] as DataTable;

        foreach (GridViewRow gvrTo in gvTo.Rows)
        {
            CheckBox chkSelect = gvrTo.FindControl("chkSelect") as CheckBox;

            if (chkSelect.Checked == true)
            {
                Label lblMember_Id = gvrTo.FindControl("lblMember_Id") as Label;

                Result = objEDMS.Delete_Project_Alert_Members(ddlProject.SelectedValue, lblMember_Id.Text, Member);

            }
        }
        DataSet dsPAM = objEDMS.Get_Project_Alert_Member(ddlProject.SelectedValue);
        dtTo = dsPAM.Tables[0];
        ViewState["PAM"] = dtTo;

        DataView dvTo = dtTo.DefaultView;
        dvTo.RowFilter = "Receiver_Type=2";

        gvTo.DataSource = dvTo;
        gvTo.DataBind();

        for (int i = 0; i &lt; gvTo.Rows.Count; i++)
        {
            dtTo = dvTo.ToTable();
            DropDownList ddl = (DropDownList)gvTo.Rows[i].FindControl("ddlSortTo");
            ddl.SelectedValue = dtTo.Rows[i]["Sort_By"].ToString();

        }
    }
</code></pre>

<p><strong>This is DataBound Code:</strong></p>

<pre><code>   protected void gvTo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EIPEDMS objEDMS = new EIPEDMS();

            DataTable dtTo = ViewState["PAM"] as DataTable;

            DataView dvTo = dtTo.DefaultView;

            dvTo.RowFilter = "Receiver_Type=2";

            DropDownList ddlSortTo = (DropDownList)e.Row.Cells[2].FindControl("ddlSortTo");



            ddlSortTo.DataSource = dvTo;

            ddlSortTo.DataTextField = "Sort_By_Dup";
            ddlSortTo.DataValueField = "Sort_By_Dup";

            ddlSortTo.DataBind();

        }
    }
</code></pre>

<p><strong>This is SelectedIndexCahnged Event Code:</strong></p>

<pre><code> protected void ddlSortTo_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        EIPEDMS objEDMS = new EIPEDMS();

        DataTable dtTo = ViewState["PAM"] as DataTable;


        DataView dvTo = dtTo.DefaultView;
        dvTo.RowFilter = "Receiver_Type=2";

        DataTable dt = new DataTable();


        dt = dvTo.ToTable();
        DropDownList ddl1 = sender as DropDownList;
        foreach (GridViewRow myRow in gvTo.Rows)
        {
            DropDownList ddl = myRow.FindControl("ddlSortTo") as DropDownList;
            if (ddl.ClientID == ddl1.ClientID)
            {

                Label lblMember_Id = myRow.FindControl("lblMember_Id") as Label;
                lblMember_Id.Text = ddl1.SelectedValue;
                int index = myRow.RowIndex;//Convert.ToInt32(lblMember_Id.Text);
                dt.Rows[index]["Sort_By"] = lblMember_Id.Text;


                for (int i = 0; i &lt; dt.Rows.Count; i++)
                {
                    if (dt.Rows[i][3] != dt.Rows[i][4])
                    {
                        if (Convert.ToInt32(dt.Rows[i][3]) &lt; Convert.ToInt32(dt.Rows[i][4]))
                        {
                            int val = Convert.ToInt32(dt.Rows[i][3]);

                            do
                            {
                                for (int j = 0; j &lt; dt.Rows.Count; j++)
                                {
                                    if (val == Convert.ToInt32(dt.Rows[j][4]) &amp;&amp; val &lt; Convert.ToInt32(dt.Rows[i][4]))
                                    {
                                        val = val + 1;
                                        dt.Rows[j][4] = val;
                                    }
                                    if (val == j + 1)
                                    {
                                        dt.Rows[j][4] = dt.Rows[j][3];
                                    }
                                }

                                val++;
                            }
                            while (val &lt; Convert.ToInt32(dt.Rows[i][4]));
                        }

                        else if (Convert.ToInt32(dt.Rows[i][3]) &gt; Convert.ToInt32(dt.Rows[i][4]))
                        {
                            int val = Convert.ToInt32(dt.Rows[i][3]);

                            for (int j = val - 1; j &gt;= 0; j--)
                            {
                                if (val == Convert.ToInt32(dt.Rows[j][4]) &amp;&amp; val &gt; Convert.ToInt32(dt.Rows[i][4]))
                                {
                                    val = val - 1;
                                    dt.Rows[j][4] = val;
                                }
                                if (val == j + 1)
                                {
                                    dt.Rows[j][4] = dt.Rows[j][3];
                                }
                                dt.Rows[j][3] = dt.Rows[j][4];

                            }
                        }
                    }
                }
                dt.AcceptChanges();
                for (int i = 0; i &lt; dtTo.Rows.Count; i++)
                {
                    for (int j = 0; j &lt; dt.Rows.Count; j++)
                    {
                        if (Convert.ToInt32(dtTo.Rows[i][0]) != Convert.ToInt32(dt.Rows[j][0]))
                        {
                            dtTo.Rows[j][4] = dt.Rows[j][4];
                        }

                    }
                }

                break;
            }
        }
        //DataSet dsPAM = objEDMS.Get_Project_Alert_Member(ddlProject.SelectedValue);
        //dt= dsPAM.Tables[0];

        ViewState["PAM"] = dtTo;

        gvTo.DataSource = dt;
        gvTo.DataBind();

        //gvTo.Sort("Sort_By_Dup", SortDirection.Ascending);

        for (int i = 0; i &lt; gvTo.Rows.Count; i++)
        {

            DropDownList ddlTo = (DropDownList)gvTo.Rows[i].FindControl("ddlSortTo");
            ddlTo.SelectedValue = dt.Rows[i][4].ToString();

        }
    }
</code></pre>
