using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BookDemo.QA
{
public partial class UnSolveQuestionList : System.Web.UI.UserControl
{
    //创建BookDemoEntities实例，用于Linq to Entities操作
    BookDemoEntities ctx = new BookDemoEntities();
    protected void Page_Load(object sender, EventArgs e)
    {
        BindToGvQuestions();//将数据绑定到gvQuestions控件上
    }
    /// <summary>
    /// 将数据绑定到gvQuestions控件上
    /// </summary>
    private void BindToGvQuestions()
    {
        List<QAQuestion> questioList = (from q in ctx.QAQuestion.Include("QACatalog") //从QAQuestion查询，并关联QACatalog
                                        where q.State == 0          //查询状态为“未解决”
                                        orderby q.Id descending     //按Id倒序排列
                                        select q).ToList();         //返回List
        gvQuestions.DataSource = questioList;//将questioList作为gvQuestions的数据源
        gvQuestions.DataBind();//将数据绑定到gvQuestions控件上
    }
}
}