Gridview中的列不匹配错误-使用超链接字段

本文关键字:超链接 字段 错误 不匹配 Gridview | 更新日期: 2023-09-27 18:15:50

我使用gridview动态地从List中选择列。列表还有一个附件字段。我把附件文件url放在变量attach中。

Ex: attach = "http: //sok:1234/Lists/CapabilityTableSales/attachments/1/Dashboard Solutions.pptx"

我使用了以下代码!!

private void PopulateGrid()
        {
           try
            {
                // List is Hard Coded here . we can also use current Context instead//
                string SiteListURL = "http://sok:1234/Lists/Case%20Studies/";

                using (SPSite oSiteCollection = new SPSite(SiteListURL))
                {
                    using (SPWeb web = oSiteCollection.OpenWeb())
                    {
                        DataTable dt = new DataTable();
                        SPQuery query = new SPQuery();
                        query.Query = "";
                        if (txt_Search.Text != String.Empty)
                        {
                            txt_Search.Text = "Key1";
                            query.Query = @"<Where><Contains><FieldRef Name='Key%20words' /><Value Type='Text'>" + txt_Search.Text + "</Value></Contains></Where>";
                        }
                        query.ViewFields = String.Concat(
                            "<FieldRef Name='Title' />",
                            "<FieldRef Name='Key%20words' />",
                            "<FieldRef Name='Project%20Brief' />",
                            "<FieldRef Name='Execution%20Highlights' />");
                        query.ViewFieldsOnly = true;
                        SPList list = web.Lists["Case Studies"];
                        SPListItemCollection col = list.GetItems(query);
                        dt = web.Lists["Case Studies"].GetItems(query).GetDataTable();
                        dt.Columns.Add(new DataColumn("Attachment", typeof(HyperLink)));
                        foreach (DataRow drow in dt.Rows)
                        {
                            drow["Attachment"] = getURL(drow["Title"].ToString());
                            //Where the function getURL will return the attachment URL!! (Working Fine)
                        }
                        GridView1.DataSource = dt;
                        GridView1.DataBind();
                    }
                }
           }
            catch (Exception ex)
            {
                //throw ex;
            }
        }

如何为drow["Attachment"] = getURL(drow["Title"].ToString());行获得列不匹配错误

我的要求是打开文件(ppt)点击该URL。

多谢! !

Gridview中的列不匹配错误-使用超链接字段

听起来像是数据类型不匹配。我猜你的getResult正在返回类型以外的东西:HyperLink,这是你的数据行所期望的。