是否可以在GridView上有两个数据源? (LINQ +数据表)

时间:2018-06-26 22:29:44

标签: c# linq gridview sharepoint datatable

我正在构建一个GridView,我想拥有自定义的列和行,这些列和行需要使用我收集到的DataTable。为了用数据填充GridView,我使用LINQ查询共享点列表,然后将其填充到GridView。

我有一个使用LINQ自己创建动态gridview的工作实例,但这似乎不允许我添加不是LINQ查询生成的任何列或行。旨在完成。有人吗?

这是我的一些代码:

 private void BindGrid()
    {

        DataTable dt = new DataTable(); //declare table upfront

        //string txtBox = txtTPP.Text;
        string dropFS = ddlFundingSource.SelectedItem.Text;
        string dropCN = ddlContractorName.SelectedItem.Text;
        var radioBox = radioForms.Text;

        SPWeb thisweb = SPContext.Current.Web;

        //begins cycling through the logic of the four lists, making comparisons. all have unique fields so this is a factor as well.
        //DataContext teamSite = new DataContext(SPContext.Current.Web.Url);
        //above is way to grab the URL wh en the site is unknown. makes it much more dynamic.
        using (TPPCodeDataContext dataContext = new TPPCodeDataContext("http://hsphxvsp2010t:20103"))
        {
            formAGrid.DataSource = null;
            formAGrid.DataBind();
            formBGrid.DataSource = null;
            formBGrid.DataBind();
            formCGrid.DataSource = null;
            formCGrid.DataBind();
            formDGrid.DataSource = null;
            formDGrid.DataBind();

            if (radioBox == "Form A" && dropFS != "-select Funding Source-")
            {
                var tppQuery = from li in dataContext.FormAList.ToList()
                               where li.FundingSource == dropFS
                               select new
                               {
                                   li.Title,
                                   li.FundingSource,
                                   li.ContractorName,
                                   li.FiscalYear,
                                   li.Total,
                               };

                if (tppQuery != null && tppQuery.Count() != 0)
                    //enumerate through result set
                    foreach (var results in tppQuery)
                    {
                        //here is where to create the boundfields or templatefields, columns.
                    }

                else lblResult.Text = "There are no results to display.";
                lblReport.Visible = true;
                lblReport.Text = dropFS;
                formAGrid.AutoGenerateColumns = false;
                formAGrid.DataSource = tppQuery;
                formAGrid.DataBind();

如您所见,我将linq语句(tppQuery)链接为gridView的数据源,但是这对我造成了进一步的束缚,使我无法进一步自定义结果的gridview(设置了一些具有数据字段属性的boundfields )。当我这样做时,gridview会很好地生成,我会得到所需的信息,但是正如我所说,我需要重新排列一些返回的信息以及生成自定义列/行。

0 个答案:

没有答案