This is a migrated thread and some comments may be shown as answers.

RowClick Postback/Select and AjaxManager

3 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
S. Webb
Top achievements
Rank 1
S. Webb asked on 09 Sep 2010, 03:39 PM
Hi,

I have a grid that displays a list of items that when clicked on populates another section with data using the AjaxManager. This works great, the problem is that when I try to incorporate paging of the grid after I select one item it won't let me select another. To incorporate paging I included the grid control in the "UpdatedControls" area of the AjaxManager. When I remove it from the manager my row select functionality returns but it will no longer page my grid data. Below is my sample code, any help would be appreciated.

Thanks,

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="blogPostGrid">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rptImages"></telerik:AjaxUpdatedControl>
                <telerik:AjaxUpdatedControl ControlID="blogPostGrid"></telerik:AjaxUpdatedControl>
                <telerik:AjaxUpdatedControl ControlID="litTitle"></telerik:AjaxUpdatedControl>
                <telerik:AjaxUpdatedControl ControlID="litDate"></telerik:AjaxUpdatedControl>
                <telerik:AjaxUpdatedControl ControlID="litContent"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
  
<div class="blogBox">
    <div class="blogContent">
        <div class="blogTitle"><asp:Literal ID="litTitle" runat="server"></asp:Literal></div>
        <div class="blogDate"><asp:Literal ID="litDate" runat="server"></asp:Literal></div>
        <div class="blogText blogTextLess"><asp:Literal ID="litContent" runat="server"></asp:Literal></div>            <div id="divImages" runat="server" class="thumbnails">
                <asp:Repeater ID="rptImages" runat="server">
                    <HeaderTemplate>
                        <h2>Blog Post Images</h2>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div class="thumbnail">
                            <img src="<%# DataBinder.Eval(Container.DataItem, "Url").ToString().Replace("~","") %>.tmb?width=75&height=75&decreaseOnly=true"/></div>
                    </ItemTemplate>
                </asp:Repeater>
                <div class="clearFix"></div>
            </div>
            <div id="div1" runat="server">
                <h2>Recent Blog Posts</h2>    
                <telerik:RadGrid ID="blogPostGrid" OnNeedDataSource="blogPostGrid_NeedDataSource"  OnItemCommand="blogPostGrid_ItemCommand" AllowPaging="true" runat="server" AutoGenerateColumns="False" GridLines="None" ShowHeader="False" BorderStyle="None">
                    <PagerStyle Mode="NumericPages"></PagerStyle>
                    <MasterTableView DataKeyNames="ID" GridLines="None" PageSize="5">
                        <RowIndicatorColumn Visible="False"></RowIndicatorColumn>
                        <ExpandCollapseColumn Visible="False" Resizable="False">
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="Title" HeaderText="Title"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Date" HeaderText="Date"></telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings EnablePostBackOnRowClick="true">
                        <Selecting AllowRowSelect="true" />
                    </ClientSettings>
                </telerik:RadGrid>
            </div>
        </div>
  
    </div>
</div>

protected void blogPostGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
 {
     BindBlogPosts();
 }
 protected void blogPostGrid_ItemCommand(object source, GridCommandEventArgs e)
 {
     if(e.CommandName == "RowClick")
         LoadPlayerBlogByID(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
 }

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 10 Sep 2010, 01:33 PM
Hello Steve,

The problem is most probably due to the way you are binding your grid. Could you paste your whole code-behind. Meanwhile you can go through the following online examples and the related help articles which should prove relevant in your case:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/simplebinding/defaultcs.aspx

Regards,
Tsvetoslav
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
0
S. Webb
Top achievements
Rank 1
answered on 10 Sep 2010, 02:05 PM
Hi Tsvetoslav,

Below is my code-behind. It is for a Sitefinity user control.

Basically the control loads the most recent Sitefinity blog post from a player and then allows the user to select a post from a paged list of recent posts.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Telerik.Cms.Engine;
using Telerik.Cms.Web.UI;
using Telerik.Web.UI;
  
public partial class Sitefinity_UserControls_Custom_blogBox : System.Web.UI.UserControl
{
    private int _ID = 0;
  
  
  
    [Category("Blog Details")]
    [DisplayName("P ID")]
    public int PID
    {
        get
        {
             return _ID;
        }
        set
        {
            _ID = value;
        }
    }
  
  
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (!IsPostBack)
            LoadPlayerBlog();
    }
  
    private void LoadPlayerBlog()
    {
        Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
  
        IMetaSearchInfo[] filter = new IMetaSearchInfo[] 
        
            new MetaSearchInfo(MetaValueTypes.ShortText, "PID", PID.ToString() ,SearchCondition.Equal),
            new MetaSearchInfo(MetaValueTypes.ShortText, "Category", "Profile Blog",SearchCondition.Equal)
        };
  
        IList listOfBlogPosts = blogManager.Content.GetContent(0, 1, "Publication_Date DESC", filter);
  
        if (listOfBlogPosts.Count > 0)
        {
            litTitle.Text = ((IContent)listOfBlogPosts[0]).GetMetaData("Title").ToString();
            litDate.Text = ((IContent)listOfBlogPosts[0]).GetMetaData("Publication_Date").ToString();
            litContent.Text = ((IContent)listOfBlogPosts[0]).Content.ToString();
              
            LoadPlayerBlogPostImages(((IContent)listOfBlogPosts[0]).ID.ToString());
            BindBlogPosts();
            blogPostGrid.DataBind();
        }
        else
        {
            this.Visible = false;
        }
  
    }
  
    private void LoadPlayerBlogByID(string blogPostID)
    {
        Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
        Telerik.Cms.Engine.IContent blogPost = blogManager.Content.GetContent(new Guid(blogPostID));
  
        if (blogPost != null)
        {
            litTitle.Text = blogPost.GetMetaData("Title").ToString();
            litDate.Text = blogPost.GetMetaData("Publication_Date").ToString();
            litContent.Text = blogPost.Content.ToString();
              
            LoadPlayerBlogPostImages(blogPost.ID.ToString());
        }
    }
  
    private void LoadPlayerBlogPostImages(string _BlogPostID)
    {
        Telerik.Libraries.LibraryManager libraryManager = new Telerik.Libraries.LibraryManager();
  
        IMetaSearchInfo[] filter = new IMetaSearchInfo[] 
        
            new MetaSearchInfo(MetaValueTypes.ShortText, "BlogPostID", _BlogPostID.ToString(), SearchCondition.Equal),
            new MetaSearchInfo(MetaValueTypes.ShortText, "Category", "Blog Images",SearchCondition.Equal)
        };
  
        IList listOfImages = libraryManager.GetContent(filter);
  
        rptImages.DataSource = listOfImages;
        rptImages.DataBind();
  
        if (listOfImages.Count == 0)
        {
            rptImages.Visible = false;
        }
        else
        {
            rptImages.Visible = true;
        }
    }
  
  
    protected void blogPostGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        BindBlogPosts();
    }
  
    protected void blogPostGrid_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "RowClick")
            LoadPlayerBlogByID(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
    }
  
    private void BindBlogPosts()
    {
        var lsPosts = new List<BlogPost>();
  
        Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
  
        IMetaSearchInfo[] filter = new IMetaSearchInfo[] 
        
            new MetaSearchInfo(MetaValueTypes.ShortText, "PID", PID.ToString() ,SearchCondition.Equal),
            new MetaSearchInfo(MetaValueTypes.ShortText, "Category", "Profile Blog",SearchCondition.Equal)
        };
  
        IList listOfBlogPosts = blogManager.Content.GetContent(0, 10, "Publication_Date DESC", filter);
  
        foreach (Telerik.Cms.Engine.IContent item in listOfBlogPosts)
        {
            BlogPost bp = new BlogPost();
  
            bp.Content = item.Content.ToString();
            bp.Title = item.GetMetaData("Title").ToString();
            bp.Date = item.GetMetaData("Publication_Date").ToString();
            bp.ID = item.ID.ToString();
  
            lsPosts.Add(bp);
        }
  
        blogPostGrid.DataSource = lsPosts;
    }
      
    public class BlogPost
    {
        public String ID { get; set; }
        public String Title { get; set; }
        public String Date { get; set; }
        public String Content { get; set; }
    }
}

Thanks,
0
Tsvetoslav
Telerik team
answered on 15 Sep 2010, 03:01 PM
Hello  Webb,

Did you get the chance to go through the online examples which links are given in my previous post. Please, note that you need to rework your code to use advanced databinding for the grid. That means that you should pass the data to the grid only in the need data-source event (you already have that) and whenever there is the need to populate the grid with new data you should modify the undleryging data-source and call the grid's Rebind() (not DataBind()) method.

Hope this information will prove helpful.

Regards,
Tsvetoslav
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
Tags
Grid
Asked by
S. Webb
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
S. Webb
Top achievements
Rank 1
Share this question
or