如何在gridview中显示SharePoint自定义列表多个附件和列数据 [英] How to display SharePoint Custom List multiple attachments and with columns data in gridview

查看:81
本文介绍了如何在gridview中显示SharePoint自定义列表多个附件和列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我要求在带有附件的gridview中显示SharePoint列表项(多个附件也附加到单个项目)。




MercuryMan

解决方案


请将列表数据和项目附件绑定到Gridview,如下所示:


Aspx页面代码:

< asp:GridView ID = " GridView1" RUNAT = QUOT;服务器" ShowHeader = QUOT假QUOT;可见= QUOT假QUOT;的AutoGenerateColumns = QUOT假QUOT;> 
< Columns>
< asp:HyperLinkField DataTextField =" Title" DataNavigateUrlFields = QUOT; URL">< / ASP:HyperLinkField字段>
< / Columns>
< / asp:GridView>

代码背后:

尝试
{
SPWeb oWeb = SPContext.Current.Web;
SPListItem nitem = oWeb.Lists [" UrListName"]。GetItemById(id);
DataTable table = new DataTable();
table.Columns.Add(" Title",typeof(string));
table.Columns.Add(" URL",typeof(string));
foreach(nitem.Attachments中的字符串attachmentname)
{
DataRow row = table.NewRow();
row [" Title"] = attachmentname;
row [" URL"] = nitem.Attachments.UrlPrefix + attachmentname;
table.Rows.Add(row);
}
table.AcceptChanges();
GridView1.Visible = true;
GridView1.DataSource = table.DefaultView;
GridView1.DataBind();
}
catch(Exception ex)
{
// throw ex;
}

更多信息:


在GridView中显示每个项目的SharePoint列表附件


谢谢


最好的问候


Hi all,

I have a requirement to display SharePoint list items in gridview with attachment (multiple attachment is attached to single item also).


MercuryMan

解决方案

Hi,

Please bind list data and item attachments into Gridview like below:

Aspx page code:

<asp:GridView ID="GridView1" runat="server" ShowHeader="false" Visible="false" AutoGenerateColumns="false">
                <Columns>
                    <asp:HyperLinkField DataTextField="Title" DataNavigateUrlFields="URL"></asp:HyperLinkField>
                </Columns>
 </asp:GridView>

Code behind:

try
            {
               SPWeb oWeb = SPContext.Current.Web;
                SPListItem nitem = oWeb.Lists["UrListName"].GetItemById(id);
                DataTable table = new DataTable();
                table.Columns.Add("Title", typeof(string));
                table.Columns.Add("URL", typeof(string));
                foreach (String attachmentname in nitem.Attachments)
                {
                    DataRow row = table.NewRow();
                    row["Title"] = attachmentname;
                    row["URL"] = nitem.Attachments.UrlPrefix + attachmentname;
                    table.Rows.Add(row);
                }
                table.AcceptChanges();
                GridView1.Visible = true;
                GridView1.DataSource = table.DefaultView;
                GridView1.DataBind();
            }
   catch (Exception ex)
            {
                //throw ex;
            }

More information:

Display SharePoint List Attachments of Each Item In GridView

Thanks

Best Regards


这篇关于如何在gridview中显示SharePoint自定义列表多个附件和列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆