后台代码
namespace OfficeChannel.UserCenter
{
    public partial class User_manage_moviedown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            DDLClassBind();
        }
        
        public void DDLClassBind()
        {
            using (OfficeChannel.OfficeChannelDataContext ocDC = new OfficeChannel.OfficeChannelDataContext(ConfigurationManager.ConnectionStrings["OfficeChannelConnectionString_Web"].ConnectionString))
            {
                var DL = from cd in ocDC.Class_Download
                         join cl in ocDC.Class on cd.classID equals cl.classID
                         select new { downloadTime = cd.DownloadTime, classtitle = cl.classTitle };
            }
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            DDLClassBind();
        }    }
}前台代码
<asp:GridView ID="GridView1" runat="server" BorderStyle="None" CellPadding="0" GridLines="None"
 AutoGenerateColumns="False" AllowPaging="True" ShowHeader="False" OnPageIndexChanging="GridView1_PageIndexChanging"
                            PageSize="6" UseAccessibleHeader="False">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                              <asp:Label ID="ProductType" runat="server" Text='<%# Eval("downloadTime") %>' ForeColor="orangered" />
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("DownloadTime") %>' ForeColor="orangered" />
                                    
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

解决方案 »

  1.   

    DDLClassBind();
    ===============>
    if(!isPostback)
    {
    DDLClassBind();}
      

  2.   

    (!Page.IsPostBack) 加了也不行 看来还有别的错?
      

  3.   

    加个
    if(!isPostback) 

     
    }
      

  4.   

     using (OfficeChannel.OfficeChannelDataContext ocDC = new OfficeChannel.OfficeChannelDataContext(ConfigurationManager.ConnectionStrings["OfficeChannelConnectionString_Web"].ConnectionString))
                {
                    var DL = from cd in ocDC.Class_Download
                             join cl in ocDC.Class on cd.classID equals cl.classID
                             select new { downloadTime = cd.DownloadTime, classtitle = cl.classTitle };
                           
                   GridView1.DataSource = DL;               GridView1.DataBind();
                }
    我代码应该有这两句,1楼没发出来有这两句也不行 我怀疑这部分有问题。
      

  5.   

    是不是没有数据,所以不显示控件. datalist是这样.
      

  6.   


    using (OfficeChannel.OfficeChannelDataContext ocDC = new OfficeChannel.OfficeChannelDataContext(ConfigurationManager.ConnectionStrings["OfficeChannelConnectionString_Web"].ConnectionString))
                {
                    var DL = from cd in ocDC.Class_Download
                             where cd.Username=="username"
                             select new { downloadTime = cd.DownloadTime};  
                  上面查询1个表就没问题,用注释查询两个表就有问题!大哥们我哪写错了?
                             //join cl in ocDC.Class on cd.classID equals cl.classID
                             //select new { downloadTime = cd.DownloadTime, classtitle = cl.classTitle };
                   GridView1.DataSource = DL;               GridView1.DataBind();
      

  7.   

    弱弱得问一下 
    //join cl in ocDC.Class on cd.classID equals cl.classID    在这两个表得classID不是外键得时候 可以查询出结果嘛?
    //select new { downloadTime = cd.DownloadTime, classtitle = cl.classTitle };
      

  8.   

    可以啊,主要是比较他们的classID是否相同
    和键没关系的
      

  9.   

    var DL = from cd in ocDC.Class_Download
                             join cl in ocDC.Class on cd.classID equals cl.classID
                             select new { downloadTime = cd.DownloadTime, classtitle = cl.classTitle };               //在这里打印DL.Count()看看值是多少               GridView1.DataSource = DL;               GridView1.DataBind();
      

  10.   

    1、在PageLoad里面
    if(!isPostback) 

       DDLClassBind(); 
    } 2、给GridView控件邦定数据源!
      

  11.   

     var DL = from cd in ocDC.Class_Download
                             where cd.Username=="username"
                             select new { downloadTime = cd.DownloadTime};  
                  上面查询1个表就没问题,用注释查询两个表就有问题!大哥们我哪写错了?
                             //join cl in ocDC.Class on cd.classID equals cl.classID
                             //select new { downloadTime = cd.DownloadTime, classtitle = cl.classTitle };
                   GridView1.DataSource = DL;               GridView1.DataBind();=======================
    你在GridView1.DataSource = DL;之前Response.Write("<script language='javascript'>alert('"+DL.Count()+"')</script>");
    看看你的DL有没有数据
    如果没有就是查询有问题的