title: e.Row.DataItem error in gridview rowdatabound event
body: <p><img src="https://i.stack.imgur.com/yC7LZ.png" alt="enter image description here">
  I want to enable or disable a particular row according to the related user logined. So i use rowdatabound event but i have an error in this line:</p>
  
  <pre><code>DataRow drv = ((DataRowView)e.Row.DataItem).Row; 
  </code></pre>
  
  <p>In here, e.Row.DataItem has related row information. I have controlled and it has values of row. But when i want to continue, i take this error: </p>
  
  <blockquote>
    <p>Unable to cast object of type '&lt;>f__AnonymousType0<code>14[System.Int32,System.Int32,System.String,System.String,System.DateTime,System.String,System.String,System.String,System.String,System.String,System.String,System.Nullable</code>1[System.DateTime],System.String,System.Nullable`1[System.Boolean]]' to type 'System.Data.DataRowView'. </p>
  </blockquote>
  
  <p>Then I have changed this line: </p>
  
  <pre><code>DataRowView drv = e.Row.DataItem as DataRowView;
  </code></pre>
  
  <p>For this condition, it gives no error but drv has still null value. Dataitem does not assign its value.</p>
  
  <p>In here, related full code:</p>
  
  <pre><code>protected void gvListele_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      dbeDataContext db = new dbeDataContext();
      var c = (from v in db.CAGRIs where v.UserID != Convert.ToInt32(Session["user"]) select v).ToArray();
      if (c != null)
      {
          foreach (var item in c)
          {
              if (e.Row.RowType == DataControlRowType.DataRow)
              {
                   DataRow drv = ((DataRowView)e.Row.DataItem).Row; 
  
                  int tempID = Convert.ToInt32(drv["CagriID"].ToString());
                  if (item.CagriID == tempID)
                  {
                      e.Row.Enabled = false;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>What can i do for this error ? Thanks in advance.</p>