title: Bind Datatable to a Repeater
body: <p>I'm trying to bind a datatable to a repeater on aspx. I'm getting the below mentioned error at "DataBind" method. I'm tired of trying to fix this since yesterday. This is the code I have:</p>
  
  <p>ASPX:</p>
  
  <pre><code>&lt;asp:Repeater ID="HistoryList" runat="server"&gt;
    &lt;HeaderTemplate&gt;
      &lt;table class="dataTable" style="width:100%;border-collapse: collapse;padding:0px 0px 0px 0px;"&gt;
        &lt;tr&gt;
          &lt;td class="dataHeaderCell"&gt;#&lt;/td&gt;
          &lt;td class="dataHeaderCell"&gt;Date&lt;/td&gt;
          &lt;td class="dataHeaderCell"&gt;Dealer&lt;/td&gt;
          &lt;td class="dataHeaderCell"&gt;Security&lt;/td&gt;
          &lt;td class="dataHeaderCell"&gt;Bid&lt;/td&gt;
       &lt;/tr&gt;
    &lt;/HeaderTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;td class="dataCell right" title='&lt;%# DataBinder.Eval(Container.DataItem, "HistoryId") %&gt;'&gt;&lt;%# Container.ItemIndex + 1 %&gt;&lt;/td&gt;
          &lt;td class="dataCell"&gt;&lt;%# (null != DataBinder.Eval(Container.DataItem, "EffectiveDate")) ? ((DateTime)DataBinder.Eval(Container.DataItem, "EffectiveDate")).ToString("d") : "..."%&gt;&lt;/td&gt;
          &lt;td class="dataCell"&gt;&lt;%# DataBinder.Eval(Container.DataItem, "OrganizationName") %&gt;&lt;/td&gt;
          &lt;td class="dataCell nowrap"&gt;&lt;a target="_blank" title="Click Here to View Name..." href='NameView.aspx?page=27&amp;nid=&lt;%# DataBinder.Eval(Container.DataItem, "SecurityId") %&gt;'&gt;&lt;%# (60587 == (int)DataBinder.Eval(Container.DataItem, "NameId")) ? DataBinder.Eval(Container.DataItem, "Expr1").ToString() + " (Unknown)" : DataBinder.Eval(Container.DataItem, "Name").ToString() %&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td class="dataCell nowrap"&gt;&lt;%# DataBinder.Eval(Container.DataItem, "Bid") %&gt;&lt;/td&gt;
      &lt;/ItemTemplate&gt;
    &lt;/table&gt;
  &lt;/asp:Repeater&gt;  
  </code></pre>
  
  <p>CS.aspx:</p>
  
  <pre><code>  string dbConnect = System.Configuration.ConfigurationManager.AppSettings["dbConnect"].ToString();
    SqlConnection thisConnection = new SqlConnection(@dbConnect);
    thisConnection.Open();
  
    SqlCommand customCommand = new SqlCommand(queryString.ToString());
    customCommand.Connection = thisConnection;
    customCommand.CommandType = System.Data.CommandType.Text;
  
    DataTable dt = new DataTable();
    SqlDataAdapter adapter = new SqlDataAdapter(customCommand4);
    adapter.Fill(dt);
  
    DataTable newsDataTable = new DataTable();
  
    foreach(DataRow dr in dt.Rows)
    {
      //check for something 
      if (true)
      {
          newsDataTable.ImportRow(dr);
      }
    }
  
    if (0 &lt; newsDataTable.Rows.Count)
    {
      HistoryList.DataSource = newsDataTable;
      HistoryList.DataBind();
      HistoryList.Visible = true;
      HistoryTitle.Text = string.Format(HistoryTitle.Text, HistoryColor.Count);
    }
  </code></pre>
  
  <p>The error I'm struggling with is:</p>
  
  <pre><code>    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'HistoryId'. ---&gt;    at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
         at System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
         at System.Web.UI.DataBinder.Eval(Object container, String expression)
         at ASP.comps_aspx.__DataBind__control60(Object sender, EventArgs e) in c:\Users\sk\Documents\Visual Studio 2013\Projects\DynamicWeb\Comps.aspx:line 562
         at System.Web.UI.Control.OnDataBinding(EventArgs e)
         at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
         at System.Web.UI.Control.DataBind()
         at System.Web.UI.Control.DataBindChildren()
         at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
         at System.Web.UI.Control.DataBind()
         at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
         at System.Web.UI.WebControls.Repeater.AddDataItemsIntoItemsArray(IEnumerable dataSource, Boolean useDataSource)
         at System.Web.UI.WebControls.Repeater.PostGetDataAction(IEnumerable dataSource)
         at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
         at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
         at System.Web.UI.WebControls.Repeater.DataBind()
         at ClarityDynamicWeb.Comps.Page_Load(Object sender, EventArgs e) in c:\Users\sk\Documents\Visual Studio 2013\Projects\DynamicWeb\Comps.aspx.cs:line 593
  </code></pre>
  
  <p>Can anyone please point out what I'm missing or doing wrong? Thank you.</p>