1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Accessing records in the News Module

Accessing records in the News Module

4 posts, 2 answered
  1. Richard
    Richard avatar
    77 posts
    Registered:
    24 Oct 2007
    12 Apr 2010
    Link to this post
    Hi,

    I would really like to create a custom controls for the News Items module that scrolls using one of the Telerik RadControls (Rotator, I believe).  My initial issue is accessing the source for the News Module.  Does anyone know where these items are stored and if there is a stored proc that can be executed to return a dataset of the news items?

    Thank you

    R
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Apr 2010
    Link to this post
    Hi Richard,

    You do not have to work with the database. You could use the API. Below is a sample implementation of a Repeater control bound to all news items

    <telerik:RadRotator  runat="server"  ID="Rotator1" Width="300" Height="50"  RotatorType="AutomaticAdvance">
      <ItemTemplate>
       <asp:Label runat="server" ID="Label1"></asp:Label>
      </ItemTemplate>
    </telerik:RadRotator>

    protected void Page_Load(object sender, EventArgs e)
      {
          var newsManager = new ContentManager("News");
          Rotator1.DataSource = newsManager.GetContent("Publication_Date DESC");
          Rotator1.ItemDataBound += new RadRotatorEventHandler(Rotator1_ItemDataBound);
          Rotator1.DataBind();
      }
     
      void Rotator1_ItemDataBound(object sender, RadRotatorEventArgs e)
      {
          var lbl = e.Item.FindControl("Label1") as Label;
          var item = e.Item.DataItem as IContent;
          lbl.Text = (string)item.GetMetaData("Title");
      }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  3. Richard
    Richard avatar
    77 posts
    Registered:
    24 Oct 2007
    14 Apr 2010
    Link to this post
    Any chance I could get a VB version of this please? I tried the code converter but ran in to a few issues when testing it.

    EDIT:

    I just tried accessing the item newsManager.GetContent.Item(0), can't seem to access the "Title" property.  How does one locate it please?

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Apr 2010
    Link to this post
    Hello Richard,

    Here is the code in VB

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
           Dim newsManager = New ContentManager("News")
           Rotator1.DataSource = newsManager.GetContent("Publication_Date DESC")
           AddHandler Rotator1.ItemDataBound, AddressOf Rotator1_ItemDataBound
           Rotator1.DataBind()
       End Sub
     
       Private Sub Rotator1_ItemDataBound(ByVal sender As Object, ByVal e As RadRotatorEventArgs)
     
           Dim lbl = TryCast(e.Item.FindControl("Label1"), Label)
           Dim item = TryCast(e.Item.DataItem, IContent)
           lbl.Text = DirectCast(item.GetMetaData("Title"), String)
       End Sub


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
Register for webinar
4 posts, 2 answered