English 中文(简体)
获取 ASP 控制的现场价值
原标题:Sitecore Accessing Field value to ASP Control

Can any one tell me if I can use a ASP Control instead of Field Renderer to display the field.Please see below illustration. Note:I need to do it in the Item Databound Event of Repeater.

我有一个模板, 显示字段为外部链接 。 例如 : 联系美国 。 在页面中显示该链接的一个方法就是 使用下面的字段创建器 。

联系人US. aspx :

<asp:Repeater ID="rptContactUS" runat="server" OnItemDataBound="Menu_OnItemDataBound">
        <ItemTemplate>
           <item><sc:FieldRenderer ID="frContactUS" runat="server"/></item>                                           
       </ItemTemplate>    
 </asp:Repeater>

联系人US.aspx.cs:

protected void Menu_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Field item = (Field)e.Item.DataItem;
        if (item != null)
        {
            FieldRenderer frContactUS= (FieldRenderer)e.Item.FindControl("frContactUS");
            if (frContactUS!= null)
            {
                frContactUS.FieldName = item.Name;
            }
        }    
    }

上述代码运作正常。 我的问题是, 我是否可以使用 Asp 控制来代替 FieldRenderer, 并且将链接的链接值从 Field 项指定为 asp href 属性, 在项目中包含数据的事件中, 中继器中的链接属性。 如果是, 请告诉我 如何?

Thanks, Suhas

最佳回答

Yes you can. From what I see in your example you are binding Field to the Menu. You could also bind a List of Items to your menu. You can then retrieve the item s fields in the repeater like this:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Item dataItem = (Item)e.Item.DataItem;
                    System.Web.UI.WebControls.HyperLink hl = (System.Web.UI.WebControls.HyperLink)e.Item.FindControl("hl");

                    if (hl != null)
                    {
                    Sitecore.Data.Fields.LinkField url = dataItem.Fields["linkfield"];

                    if (url != null)
                    {
                        hlMerk.NavigateUrl = url.Url;
                        hlMerk.Target = url.Target;
                        // more properties are available check sitecore documentation
                    时 时                       
                时 时
           时 时

时 时

From here you will have the url field (obviously you should give the correct field name instead of url. The LinkField has several properties as described in the general Sitecore documentation that can be found @ http://sdn.sitecore.net.

问题回答

暂无回答




相关问题
How do I hook the Save event in Sitecore Page Editor?

I m creating a custom edit control for my content authors to use in the Page Editor. Of course this means I want my control to save data to an Item when the user clicks on the Save button. How is ...

Passing Parameters to a Sitecore Sublayout

I ve done this before with a web control, but I can t seem to get it to work with a sublayout. On the Presentation Details for a particular item I m assigning my Sublayout and then in the additional ...

Lucene.Net Search List

I m using Sitecore and have a multilist field I d like to use Lucene to search on. The problem I have is that the field is a pipe-delimited list of actual values and there could be between 0 and an ...

Test for Descendant Items

I am trying to create a simple inventory of items in a Sitecore website using an xslt. The problem is that I can t find a way to test whether an item has descendant items beneath it. It s easy to ...

Sitecore set/change default language from en

Can anyone recommend the best way to change the default language in Sitecore 6.1. On a fresh install, the typical language for all items is en English, witha nice little USA flag and all. However, ...

热门标签