【问题标题】:Column Mismatch Error in Gridview - Using Hyperlink FieldGridview 中的列不匹配错误 - 使用超链接字段
【发布时间】:2011-11-28 09:05:59
【问题描述】:

我使用gridview 从列表中动态选择列。这些列表也有一个附件字段。所以我在一个名为 attach 的变量中有附件文件 url。

例如: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()); 行出现列不匹配错误

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

非常感谢!!

【问题讨论】:

    标签: c# asp.net gridview sharepoint-2010 attachment


    【解决方案1】:

    听起来像是数据类型不匹配。我猜你的 getResult 返回的不是类型:HyperLink 这是你的数据行所期望的。

    【讨论】:

    • 我不确定,我的结果是“http://sok:1234/Lists/CapabilityTableSales/attachments/1/Dashboard Solutions.pptx”。我想要一个指向此 URL 的超链接...
    • 看起来您可能必须使用 SPMenu 字段。有关详细信息,请参阅此处 - blogs.msdn.com/b/powlo/archive/2007/02/25/…
    • 通过将超链接字段更改为字符串字段并使用锚模板 HREF 属性作为附件 URL 来摆脱它。
    猜你喜欢
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多