title: First row of DataGrid not being filled in with DataList data
body: <p>I have a DataGrid with 4 columns and a DataList with 5 columns. The DataList resides inside the DataGrid as another separate column by itself.
  Everything is coming out fine, except that the first row in the datagrid does not display the contents of the datalist. It's as if everything in my datalist should be pushed up by a 1 row to display the data correctly.</p>
  
  <p>I have validated (during debugging) that the data is coming out fine in the datalist for the corresponding first row of the datagrid, but it doesn't get rendered on the first row of the datagrid. It starts to get rendered on the second row of the datagrid.</p>
  
  <p>I've been over this numerous times with the markup and the codebehind, and can't figure out why this is happening. Any help would be appreciated.</p>
  
  <p>Below is my code:</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="referrals.ascx.cs" Inherits="dpbrokers.dpbrokers.referrals"
      TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %&gt;
  &lt;div align="center"&gt;
      &lt;asp:Label ID="errormessage" runat="server" Visible="False" /&gt;&lt;/div&gt;
  &lt;asp:DataGrid ID="lstReferrals" runat="server" DataKeyField="ReferringAffiliateID"
      AutoGenerateColumns="false" CellPadding="4" OnItemDataBound="lstReferrals_ItemDataBound"&gt;
      &lt;AlternatingItemStyle Font-Size="9pt" CssClass="small" BackColor="#C2D6FA"&gt;&lt;/AlternatingItemStyle&gt;
      &lt;ItemStyle Font-Size="9pt" CssClass="small" BackColor="White"&gt;&lt;/ItemStyle&gt;
      &lt;HeaderStyle Font-Size="11pt" Font-Bold="True" ForeColor="White" BackColor="#ABACAD"&gt;
      &lt;/HeaderStyle&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateColumn HeaderText="Referring Affiliate"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:HyperLink Text='&lt;%# DataBinder.Eval(Container.DataItem, "ReferringAffiliateName") %&gt;'
                      NavigateUrl='&lt;%# EditURL("Referral",DataBinder.Eval(Container.DataItem, "ReferralID").ToString(),"Edit",0) %&gt;'
                      runat="server" ID="Hyperlink1" /&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateColumn&gt;
          &lt;asp:TemplateColumn HeaderText="SkyCard Awarded"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="itemAward" runat="server" Text='&lt;%# IsAwarded(DataBinder.Eval(Container.DataItem, "IsAwarded").ToString()) %&gt;' /&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateColumn&gt;
          &lt;asp:BoundColumn DataField="DSMAffiliateName" HeaderText="District Sales Manager"&gt;
          &lt;/asp:BoundColumn&gt;
          &lt;asp:BoundColumn DataField="DSMAffiliatePhone" HeaderText="DSM Phone"&gt;&lt;/asp:BoundColumn&gt;
          &lt;asp:TemplateColumn&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:DataList ID="DetailList" ItemStyle-CssClass="small" DataSource="&lt;%# riReferrals %&gt;"
                      runat="server" Width="100%"&gt;
                      &lt;HeaderTemplate&gt;
                          &lt;table width="100%" cellpadding="4" border="1"&gt;
                              &lt;tr bgcolor="#ABACAD" class="normalwhite"&gt;
                                  &lt;td width="25%"&gt;
                                      Referral Name
                                  &lt;/td&gt;
                                  &lt;td width="20%"&gt;
                                      Phone Number
                                  &lt;/td&gt;
                                  &lt;td width="30%"&gt;
                                      Email
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      Referred On
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      Is Member?
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                      &lt;/HeaderTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;tr class="small"&gt;
                              &lt;td&gt;
                                  &lt;asp:HyperLink Text='&lt;%# DataBinder.Eval(Container.DataItem, "ContactName") %&gt;' NavigateUrl='&lt;%# EditURL("ReferralID",DataBinder.Eval(Container.DataItem, "ReferralID").ToString(),"Edit",0)  %&gt;'
                                      runat="server" ID="Hyperlink2" /&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;%# FormatPhone(DataBinder.Eval(Container.DataItem,"Phone").ToString()) %&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  &lt;%# FormatForEmail(DataBinder.Eval(Container.DataItem, "Email").ToString())%&gt;
                              &lt;/td&gt;
                              &lt;td&gt;
                                  (&lt;%# DataBinder.Eval(Container.DataItem,"Created", "{0:g}") %&gt;)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  (&lt;%# IsMember(DataBinder.Eval(Container.DataItem, "JoinedON").ToString())%&gt;)
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;FooterTemplate&gt;
                          &lt;/table&gt;
                      &lt;/FooterTemplate&gt;
                  &lt;/asp:DataList&gt;
                  &lt;div align="right"&gt;
                      &lt;asp:ImageButton ID="Button1" CommandName="award" ImageUrl="~/images/dpbbuttons/awardbutton.gif"
                          AlternateText="Award SkyCard" runat="server" /&gt;&lt;/div&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateColumn&gt;
      &lt;/Columns&gt;
      &lt;PagerStyle Mode="NumericPages"&gt;&lt;/PagerStyle&gt;
  &lt;/asp:DataGrid&gt;
  </code></pre>
  
  <p>CODE BEHIND</p>
  
  <pre><code>public ArrayList riReferrals;
  
  
              protected void Page_Load(System.Object sender, System.EventArgs e)
              {
                  if (!Page.IsPostBack)
                      LoadReferrals();
              }
  
  
              private void LoadReferrals()
              {
                  try
                  {
                      ReferralController objReferral = new ReferralController();
                      lstReferrals.DataSource = objReferral.GetReferrals();
                      lstReferrals.DataBind();
                  }
                  catch (Exception ex)
                  {
                      Response.Write(ex);
  
                      CLogError clsLogError = new CLogError(ex, Request, Session, Context.User.Identity.Name);
                      clsLogError.LogError();
                  }
              }
  
              public void lstReferrals_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
              {
  
                  switch (e.Item.ItemType)
                  {
                      case ListItemType.Item:
                      case ListItemType.AlternatingItem:
                          lbl1 = (Label)e.Item.FindControl("itemAward");
  
                          GetDtlReferrals(Convert.ToInt32(lstReferrals.DataKeys[e.Item.ItemIndex]));
  
                          button.Visible = true;
                          if (lbl1.Text.ToLower() == "No")
                              button.Attributes.Add("onClick", "javascript:return confirm(\'Are You Sure You Wish To Award a SkyCard to this Agent ?\');");
                          else
                          {
                              button.ImageUrl = "~/images/dpbbuttons/revokebutton.gif";
                              button.Attributes.Add("onClick", "javascript:return confirm(\'Are You Sure You Wish To Revoke the SkyCard Award for this Agent ?\');");
                          }
  
                          break;
                  }
              }
  
              public ArrayList GetDtlReferrals(Int32 KeyField)
              {
                  riReferrals = null;
  
                  try
                  {
                      // Obtain a list of discussion messages for the module
                      ReferralController objReferral = new ReferralController();
                      riReferrals = objReferral.GetReferralsByAgentID(KeyField);
                  }
                  catch (Exception ex)
                  {
                      Response.Write(ex);
  
                      CLogError clsLogError = new CLogError(ex, Request, Session, Context.User.Identity.Name);
                      clsLogError.LogError();
                  }
  
                  return riReferrals;
              }
  </code></pre>