NeedDataSource and paging

5 posts, 0 answers
  1. Johnny
    Johnny avatar
    16 posts
    Member since:
    Mar 2009

    Posted 30 Jan 2011 Link to this post

    Hi,

    I´m making a custom Sitefinity control and I have some problems getting the RadListView and RadDataPager to function with the AjaxManagerProxy. I think I need to set the AjaxManager in code behind due to sitefinity,  but I can´t get it to work properly. The control loads with 3 paging buttons and if I click on number 2, button number 3 disapears. Also, I don´t think all the rows in the NeedDataSource gets loaded, or at least the paging don´t seem to know about it. Any ideas?

    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
    </telerik:RadAjaxManagerProxy>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
    </telerik:RadAjaxLoadingPanel>
      
    <div class="localEventContainer">
        <asp:Panel ID="ListViewPanel" runat="server">
        <div class="localEventTop"><asp:Label ID="lblControlTitle" runat="server"></asp:Label></div>
            <telerik:RadListView ID="RadListView1" runat="server" AllowPaging="True" 
                DataKeyNames="EventID" ItemPlaceholderID="EventItemContainer"
                Skin="Black" OnDataBound="RadListView1_DataBound" 
                OnNeedDataSource="RadListView1_NeedDataSource">
                <LayoutTemplate>
                    <asp:Panel ID="EventItemContainer" runat="server"></asp:Panel>
                    <table cellpadding="0" cellspacing="0" width="100%;" style="clear: both;">
                        <tr>
                            <td>
                                <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1"
                                    PageSize="5">
                                    <Fields>
                                        <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
                                        <telerik:RadDataPagerButtonField FieldType="Numeric" />
                                        <telerik:RadDataPagerButtonField FieldType="NextLast" />
                                    </Fields>
                                </telerik:RadDataPager>
                            </td>
                        </tr>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                <div class="localEventArticleContainer">
                    <div class="localEventTitle">
                        <asp:Label ID="lblEventName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                    </div>
                    <div class="localEventDate">
                        <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date", "{0:d}") %>'></asp:Label>
                        <asp:Label ID="lblTime" runat="server" Text='<%# Eval("Starttime") %>'></asp:Label>
                    </div>
                    <div class="localEventText">
                        <asp:Label ID="lblText" runat="server" Text='<%# Eval("LocationName") %>'></asp:Label>
                    </div>
                    <%--<div class="localEventLink">
                        <asp:HyperLink ID="lblLink" runat="server" Text="Ticnet.se" NavigateUrl='<%# Eval("Url") %>' Target="_blank"></asp:HyperLink>
                    </div>--%>
                </div>
                </ItemTemplate>
            </telerik:RadListView>
        </asp:Panel>
          
        <div class="localEventBottom"></div>
    </div>
    protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (this.Page != null && !this.DesignMode)
            {
                RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
                if (ajaxManager != null)
                {
                    ajaxManager.AjaxSettings.AddAjaxSetting(ListViewPanel, ListViewPanel, RadAjaxLoadingPanel1);
                }
      
                lblEventAreaID.Text = EventAreaID.ToString();
            }
        }

    protected void RadListView1_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
        {
            RadListView1.DataSource = ReadData("SELECT e.EventID, e.Name,e.Url, ev.Name AS LocationName, et.Date, et.Starttime FROM mp_Event e INNER JOIN mp_EventLocation ev ON e.EventLocationID = ev.EventLocationID INNER JOIN mp_EventTime et on e.EventID = et.EventID WHERE " + "ev.AreaID = @AreaID AND " + "et.Date >= '" + Today + "' ORDER BY Date ASC");
        }
      
        private SqlDataReader ReadData(string query)
        {
            string connString = ConfigurationManager.ConnectionStrings["UnigolfMPTestConnectionString"].ConnectionString;
            conn = new SqlConnection(connString);
            conn.Open();
      
            SqlCommand cmd = new SqlCommand(query, conn);
            cmd.Parameters.AddWithValue("@AreaID", lblEventAreaID.Text);
      
            reader = cmd.ExecuteReader();
            return reader;
        }
      
        protected void RadListView1_DataBound(object sender, EventArgs e)
        {
            reader.Close();
            conn.Close();
        }
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 03 Feb 2011 Link to this post

    Hello Johnny,

    Could you please confirm that the RadListView is displayed as expected and the paging works without any ajax? You can also check is the same works in simple web site outside Sitefinity.

    Greetings,
    Iana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Johnny
    Johnny avatar
    16 posts
    Member since:
    Mar 2009

    Posted 06 Feb 2011 Link to this post

    Hello Iana,

    I´ve been testing further and the control don´t work without ajax either. Same sort of problems that I have with ajax on. I´m running out of ideas to test.

    EDIT: Everything works as expected when I connect to a regular SqlDataSource, both with and without ajax on. Ok so it must be something wrong with my NeedDataSource event. DataReader vs DataTable? Something else I can test?

    Johnny
  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 07 Feb 2011 Link to this post

    Hi Johnny,

    You should not have any problems binding the RadListView to DataReader. However, can you try debugging the ReadData() method  and confirm it returns the proper data?

    Best wishes,
    Iana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  6. Johnny
    Johnny avatar
    16 posts
    Member since:
    Mar 2009

    Posted 08 Feb 2011 Link to this post

    Hello Iana,

    Yeah the reader return 17 rows, the same as when I query the DB in management studio. With a page size of 5 the pager would have 4 pages, correct? But on start it only shows 3 pages with the 5 first events and on click to another page it all goes horrible bad.

    Some other info:
    As I said I´m working with a sitefinity site and the version is 3.7 SP3. So this is not the latest Ajax controls.
    Would it help if I upload the control on the live site and send you the link?

    Edit: I tried using DataTable instead of DataReader and that worked. I suspect there was something wrong with the Sql parameters in the reader, but I´m not sure. The only thing now is to get the pager to look as suspected in IE.

    Thanks for the help Iana!

    /Johnny
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017