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

发布于 2024-12-18 19:48:23 字数 2587 浏览 5 评论 0原文

我使用gridview从列表中动态选择列。该列表还有一个附件字段。所以我将附件文件 url 放在一个名为 Attach 的变量中。

例如: 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)该网址的。

非常感谢!!

I used a gridview to select the columns from a List dynamically. The lists also have an attachment field. So I have the attachment file url in a variable called attach.

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

I used the following Code !!

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;
            }

        }

How ever getting a column mismatch error for the line drow["Attachment"] = getURL(drow["Title"].ToString());

My requirement is to open the file (PPTs) on click of that URL.

Many Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

划一舟意中人 2024-12-25 19:48:24

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

Sounds like a data type mismatch. I guess your getResult is returning something other than type : HyperLink which is what your data row expects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文