Bind DropDownList in asp.net in Item Template on row databound
<p>I am trying to bind a dropdown which is in a grid but I am getting error.</p>

<pre><code>&lt;asp:GridView ID="grdddl" AutoGenerateColumns="false" ShowHeader="false" OnRowDataBound="grdddl_RowDataBound" ShowFooter="true" runat="server"&gt;
                    &lt;Columns&gt;
                        &lt;asp:TemplateField&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:DropDownList ID="ddlcommtype" SelectedValue='&lt;%#Eval("ComPlanRoleDescr") %&gt;'  AutoPostBack="true" OnSelectedIndexChanged="ddlcommtype_SelectedIndexChanged" runat="server"&gt;&lt;/asp:DropDownList&gt;
                                &lt;asp:HiddenField ID="hdnid" Value='&lt;%#Eval("ID") %&gt;' runat="server" /&gt;
                            &lt;/ItemTemplate&gt;
                            &lt;FooterTemplate&gt;
                                 &lt;asp:DropDownList ID="ddlcommtypefooter"  AutoPostBack="true" OnSelectedIndexChanged="ddlcommtypefooter_SelectedIndexChanged" runat="server"&gt;&lt;/asp:DropDownList&gt;
                            &lt;/FooterTemplate&gt;
                        &lt;/asp:TemplateField&gt;

                    &lt;/Columns&gt;
&lt;/asp:GridView&gt;

protected void grdddl_RowDataBound(object sender, GridViewRowEventArgs e)
    {

            if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddlcommtype = (DropDownList)e.Row.FindControl("ddlcommtype");
            ddlcommtype.DataSource = listcommtype;
            ddlcommtype.DataTextField = "ComPlanRoleDescr";
            ddlcommtype.DataValueField = "ID";
            ddlcommtype.DataBind();


        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DropDownList ddlcommtype = (DropDownList)e.Row.FindControl("ddlcommtypefooter");
            ddlcommtype.DataSource = listcommtype;
            ddlcommtype.DataTextField = "ComPlanRoleDescr";
            ddlcommtype.DataValueField = "ID";
            ddlcommtype.DataBind();
        }
}
</code></pre>

<p><strong>This Code is giving error:</strong>
'ddlcommtype' has a SelectedValue which is invalid because it does not exist in the list of items.</p>