后台代码
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>
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>
===============>
if(!isPostback)
{
DDLClassBind();}
if(!isPostback)
{
}
{
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楼没发出来有这两句也不行 我怀疑这部分有问题。
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();
//join cl in ocDC.Class on cd.classID equals cl.classID 在这两个表得classID不是外键得时候 可以查询出结果嘛?
//select new { downloadTime = cd.DownloadTime, classtitle = cl.classTitle };
和键没关系的
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();
if(!isPostback)
{
DDLClassBind();
} 2、给GridView控件邦定数据源!
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有没有数据
如果没有就是查询有问题的