linq查询集合并分页展示数据

本文介绍了一个使用ASP.NET进行数据绑定的例子,展示了如何通过查询字符串参数获取特定问题编号的数据,并将其显示在一个评论列表中。此外,还实现了分页功能以优化大量数据的展示效果。
    private void Bind()
    {

        if (Request.QueryString["QuestionNo"] != null)
        {
            string QuestionNo = Request.QueryString["QuestionNo"].ToString();
  
            string BeginDate = DateTime.Now.AddMonths(-2).ToShortDateString();
            string EndDate = DateTime.Now.AddDays(1).ToShortDateString();
            string strWhere = "SELECT * FROM (SELECT id,QuestionNo,ServiceCode,'现场服务单' as 类型,Result,CreateDate FROM A_Service union all SELECT id,QuestionNo,ServiceCode,'未解决单' as 类型,Result,CreateDate FROM A_NotSolve) as a where 1=1";
            strWhere += "and QuestionNo ='" + QuestionNo + "' and QuestionNo<>'' and CreateDate>='" + BeginDate + "' and CreateDate<'" + EndDate + "'";
            if (ViewState["strWhere"] != null)
            {
                strWhere += ViewState["strWhere"].ToString();
            }
            DataSet ds = SqlHelper.Query(SqlHelper.LocalSqlServer, strWhere);
            if (ds.Tables[0].Rows.Count > 0)
            {
                var query = (from t in ds.Tables[0].AsEnumerable()
                             // where t.Field<string>("QuestionNo") == QuestionNo
                             select t).Skip((this.Pager.CurrentPageIndex - 1) * this.Pager.PageSize).Take(this.Pager.PageSize);
                DataTable boundTable = query.CopyToDataTable<DataRow>();
                RepeaterCommentList.DataSource = boundTable;
                RepeaterCommentList.DataBind();
                Pager.RecordCount = ds.Tables[0].Rows.Count;
            }
            else
            {
                Msg = " <tr><td colspan=\"6\" align=\"center\" valign=\"top\" bgcolor=\"#ffffff\" style=\"color:Red;font-weight:bold;\">数据为空</td></tr>";
            }

        }

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值