Gridview 中的列不匹配错误 - 使用超链接字段
我使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来像是数据类型不匹配。我猜您的 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.