开发者

Developing SharePoint custom web part. How to render lookup field?

I need to render lookup field from a list as a link with popup dialog (the same way as lookup fields are rendered in default SharePoint 2010 list view). How can I do that if I have SPListItem object that contains lookup field? Maybe there is some control to render lookup fields?

protected void Page_Init(object sender, EventArgs e)
{
    SPQuery query = new SPQuery();
    query.Query = "some query here";
    SPListItemCollection items = __list.GetItems(query);
    foreach (SPListItem item in items)
    {
        // render item["loo开发者_StackOverflow社区kup_field_name"] somehow
    }
}


spfieldlookupvalue value=new SpFiledlookupvalue(item["column name"]);
string id=value.lookupid;//you can retrieve the text,id
string text=value.lookuptext;


If a list item is retrieved by the SPQuery object it will have a value in it, all you have to check is wether the value is null or not.

foreach (SPListItem item in items)
{
    if(item != null)
    {
        // render item["lookup_field_name"] somehow
    }
}

This means that lookup columns does not get filled when you ask for them, the are filled with whatever content they carry when they are created.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜