2012-01-05 37 views
0

我有一個DataGrid有4列,DataList有5列。 DataList作爲另一個獨立的列存在於DataGrid中。 一切都很好,除了datagrid中的第一行不顯示數據列表的內容。就好像我的datalist中的所有東西都應該被向上移動一行以正確顯示數據。第一行的DataGrid沒有被DataList數據填充

我已經驗證(在調試過程中)數據在DataGrid的相應第一行的數據列表中正常出現,但它不會在數據網格的第一行呈現。它開始在數據網格的第二行呈現。

我已經在這個無數次與標記和代碼隱藏,並無法弄清楚爲什麼發生這種情況。任何幫助,將不勝感激。

下面是我的代碼:

HTML

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="referrals.ascx.cs" Inherits="dpbrokers.dpbrokers.referrals" 
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> 
<div align="center"> 
    <asp:Label ID="errormessage" runat="server" Visible="False" /></div> 
<asp:DataGrid ID="lstReferrals" runat="server" DataKeyField="ReferringAffiliateID" 
    AutoGenerateColumns="false" CellPadding="4" OnItemDataBound="lstReferrals_ItemDataBound"> 
    <AlternatingItemStyle Font-Size="9pt" CssClass="small" BackColor="#C2D6FA"></AlternatingItemStyle> 
    <ItemStyle Font-Size="9pt" CssClass="small" BackColor="White"></ItemStyle> 
    <HeaderStyle Font-Size="11pt" Font-Bold="True" ForeColor="White" BackColor="#ABACAD"> 
    </HeaderStyle> 
    <Columns> 
     <asp:TemplateColumn HeaderText="Referring Affiliate"> 
      <ItemTemplate> 
       <asp:HyperLink Text='<%# DataBinder.Eval(Container.DataItem, "ReferringAffiliateName") %>' 
        NavigateUrl='<%# EditURL("Referral",DataBinder.Eval(Container.DataItem, "ReferralID").ToString(),"Edit",0) %>' 
        runat="server" ID="Hyperlink1" /> 
      </ItemTemplate> 
     </asp:TemplateColumn> 
     <asp:TemplateColumn HeaderText="SkyCard Awarded"> 
      <ItemTemplate> 
       <asp:Label ID="itemAward" runat="server" Text='<%# IsAwarded(DataBinder.Eval(Container.DataItem, "IsAwarded").ToString()) %>' /> 
      </ItemTemplate> 
     </asp:TemplateColumn> 
     <asp:BoundColumn DataField="DSMAffiliateName" HeaderText="District Sales Manager"> 
     </asp:BoundColumn> 
     <asp:BoundColumn DataField="DSMAffiliatePhone" HeaderText="DSM Phone"></asp:BoundColumn> 
     <asp:TemplateColumn> 
      <ItemTemplate> 
       <asp:DataList ID="DetailList" ItemStyle-CssClass="small" DataSource="<%# riReferrals %>" 
        runat="server" Width="100%"> 
        <HeaderTemplate> 
         <table width="100%" cellpadding="4" border="1"> 
          <tr bgcolor="#ABACAD" class="normalwhite"> 
           <td width="25%"> 
            Referral Name 
           </td> 
           <td width="20%"> 
            Phone Number 
           </td> 
           <td width="30%"> 
            Email 
           </td> 
           <td> 
            Referred On 
           </td> 
           <td> 
            Is Member? 
           </td> 
          </tr> 
        </HeaderTemplate> 
        <ItemTemplate> 
         <tr class="small"> 
          <td> 
           <asp:HyperLink Text='<%# DataBinder.Eval(Container.DataItem, "ContactName") %>' NavigateUrl='<%# EditURL("ReferralID",DataBinder.Eval(Container.DataItem, "ReferralID").ToString(),"Edit",0) %>' 
            runat="server" ID="Hyperlink2" /> 
          </td> 
          <td> 
           <%# FormatPhone(DataBinder.Eval(Container.DataItem,"Phone").ToString()) %> 
          </td> 
          <td> 
           <%# FormatForEmail(DataBinder.Eval(Container.DataItem, "Email").ToString())%> 
          </td> 
          <td> 
           (<%# DataBinder.Eval(Container.DataItem,"Created", "{0:g}") %>) 
          </td> 
          <td> 
           (<%# IsMember(DataBinder.Eval(Container.DataItem, "JoinedON").ToString())%>) 
          </td> 
         </tr> 
        </ItemTemplate> 
        <FooterTemplate> 
         </table> 
        </FooterTemplate> 
       </asp:DataList> 
       <div align="right"> 
        <asp:ImageButton ID="Button1" CommandName="award" ImageUrl="~/images/dpbbuttons/awardbutton.gif" 
         AlternateText="Award SkyCard" runat="server" /></div> 
      </ItemTemplate> 
     </asp:TemplateColumn> 
    </Columns> 
    <PagerStyle Mode="NumericPages"></PagerStyle> 
</asp:DataGrid> 

後面的代碼

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; 
      } 

回答

0

明白了!

在GetDtlsReferrals方法,我添加其產生的顯示數據我尋找下面的代碼片斷:

DataList DetailList = (DataList)e.Item.FindControl("DetailList"); 
        DetailList.DataBind();