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 SolvedQuestionList : System.Web.UI.UserControl
    {
        //创建BookDemoEntities实例，用于Linq to Entities操作
        BookDemoEntities ctx = new BookDemoEntities();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBindToGvSolvedQuestions();//将数据绑定到gvSolvedQuestions控件上
            }
        }
        /// <summary>
        /// 将数据绑定到gvSolvedQuestions控件上
        /// </summary>
        private void DataBindToGvSolvedQuestions()
        {
            List<QAQuestion> questioList = (from q in ctx.QAQuestion.Include("QACatalog") //从QAQuestion查询，并关联QACatalog
                                            where q.State == 1          //查询状态为“已解决”
                                            orderby q.Id descending     //按Id倒序排列
                                            select q).ToList();         //返回List
            gvSolvedQuestions.DataSource = questioList;
            gvSolvedQuestions.DataBind();
        }
    }
}