title: detect grid view in edit mode at row data bound
body: <p>i just want to detect that grid view in row editing mode and i just want to bind drop down list at this moment. i found many article and i make this code </p>
  
  <p>I have this error</p>
  
  <blockquote>
    <p>DataBinding: 'AllProjects_Result' does not contain a property with
    the name 'Projects'.</p>
  </blockquote>
  
  <pre><code>  protected void GVAllProjects_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      DropDownList ddlDistrictName = null;
      DropDownList ddlPurposeName = null;
      DropDownList ddlTypes = null;
      if (e.Row.RowType == DataControlRowType.Footer &amp;&amp; e.Row.RowState == DataControlRowState.Edit)
      {
  
          ddlDistrictName = e.Row.FindControl("ddlDistrictName") as DropDownList;
          ddlPurposeName = e.Row.FindControl("ddlPurposeName") as DropDownList;
          ddlTypes = e.Row.FindControl("ddlTypes") as DropDownList;
      }
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
  
          ddlDistrictName = e.Row.FindControl("ddlDistrictName") as DropDownList;
          ddlPurposeName = e.Row.FindControl("ddlPurposeName") as DropDownList;
          ddlTypes = e.Row.FindControl("ddlTypes") as DropDownList;
      }
      if (ddlDistrictName != null)
      {
          using (AlamaarRealEstateEntities context = new AlamaarRealEstateEntities())
          {
              ddlDistrictName.DataSource = context.Districts.ToList();
              ddlDistrictName.DataTextField = "DistrictName";
              ddlDistrictName.DataValueField = "ID";
              ddlDistrictName.DataBind();
  
              ddlPurposeName.Items.Insert(0, new ListItem(""));
              ddlPurposeName.DataSource = context.Purposes.ToList();
              ddlPurposeName.DataTextField = "PurposeName";
              ddlPurposeName.DataValueField = "ID";
              ddlPurposeName.DataBind();
  
              ddlTypes.Items.Insert(0, new ListItem(""));
  
              ddlTypes.DataSource = context.Types.ToList();
              ddlTypes.DataTextField = "TypeName";
              ddlTypes.DataValueField = "ID";
              ddlTypes.DataBind();
  
          }
          if (e.Row.RowType == DataControlRowType.DataRow &amp;&amp; (e.Row.RowState &amp; DataControlRowState.Edit) == DataControlRowState.Edit)
          {
  
              ddlDistrictName.SelectedValue = (DataBinder.Eval(e.Row.DataItem, "DistrictID")).ToString();
              ddlPurposeName.SelectedValue = (DataBinder.Eval(e.Row.DataItem, "PurposeID")).ToString(); 
              ddlTypes.SelectedValue = (DataBinder.Eval(e.Row.DataItem, "TypeID")).ToString(); 
          }
      }
  }
  </code></pre>
  
  <p>the error here at those lines:</p>
  
  <pre><code>if (e.Row.RowType == DataControlRowType.DataRow &amp;&amp; (e.Row.RowState &amp; DataControlRowState.Edit) == DataControlRowState.Edit)
  {
          ddlDistrictName.SelectedValue = (DataBinder.Eval(e.Row.DataItem, "DistrictID")).ToString();
          ddlPurposeName.SelectedValue = (DataBinder.Eval(e.Row.DataItem, "PurposeID")).ToString(); 
          ddlTypes.SelectedValue = (DataBinder.Eval(e.Row.DataItem, "TypeID")).ToString(); 
  }
  </code></pre>