Linq to DataTable 操作

--- 綁定顯示列表  
 private void BindList()
        {
            DataTable dt = dal.GetList("");   // GetList("") 方法從數據庫讀取並返回DataTable對象集合
            string args = "";     //查詢參數
            if (!string.IsNullOrEmpty(this.txtvalue.Text))   // 判斷文本框輸入查詢條件
            {
                args = this.txtvalue.Text.ToString();
            }
            var vdt = from temp in dt.AsEnumerable()      // linq語句  
                      where temp["CompanyName"].ToString().StartsWith(args)
                      select new
                      {  // 集合列表Eval()方法綁定的顯示字段;
                          Comid = temp["Comid"].ToString(),
                          CompanyName = temp["CompanyName"].ToString(),
                          NCID = temp["NCID"].ToString(),
                          CreateDate = temp["CreateDate"].ToString(),
                          Phone = temp["Phone"].ToString()
                      };
            this.Repeater1.DataSource = vdt;
            this.Repeater1.DataBind();
        }
----以上的操作完全在aspx.cs的前臺頁面中的後臺頁面中書寫的,但我不清楚到底在前臺寫linq綁定號還是在 dal數據層寫好.歡迎各位dX歇息
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章