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

RadListView / RadGrid NeedDataSource

3 Answers 353 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Insad
Top achievements
Rank 2
Insad asked on 06 Dec 2010, 03:15 PM
Hello I have a problem with the NeedDataSource event of the radlistview. I tried several things but it will only bind once in the initial pageload. I also placed a radgrid on the form to see if the code and/or events are correct and they are because the radgrid is behaving as expected (click the pager or edit button and the needdatasource event is fired). What could this be? Only thing I could see in reflector is a slightly different implementation of the event if i compare the listview with the grid.

To overcome all the details i created a new sample form as below with the same problem.
ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Artikelgroepen.aspx.cs" Inherits="Drumis.ECommerce.Website.Admin.Content.Artikelgroepen" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:radscriptmanager id="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Path="~/scripts/script.js" />
        </Scripts>
    </telerik:radscriptmanager>
  
    <div>
  
      
<telerik:RadWindow runat="server" Width="750px" Height="560px" VisibleStatusbar="false" AutoSize="true"
    NavigateUrl="~/FileExplorer/Explorer.aspx" ID="ExplorerWindow" Modal="true" Behaviors="Close,Move">
</telerik:RadWindow>
  
<telerik:radcodeblock runat="server" ID="codeblock1">
<script type="text/javascript">
  
    function OpenFileExplorerDialog() {
        var wnd = $find("<%= ExplorerWindow.ClientID %>");
        wnd.show();
    }
  
    function ChangeRows() {
        var rt = document.getElementById('<%= ActiveRelatiesText.ClientID %>');
        var ht = document.getElementById('<%= RowText.ClientID %>');
  
        rt.rows = ht.value;
    }
</script>
</telerik:radcodeblock>
  
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
      
    <div id="ConfigPanel" style="margin:5px;padding:5px;border: 1px solid black;">
        <table width="100%" cellpadding="3" cellspacing="0">
            <tr>
                <td>
                    <asp:Label ID="LanguageLabel" runat="server"  meta:ResourceKey="LanguageLabel">Selecteer een taal:</asp:Label>
                </td>
                <td>
                    <telerik:RadComboBox ID="LanguageCbx" runat="server" AutoPostBack="True"></telerik:RadComboBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="RelatieHeaderLabel" runat="server"  meta:ResourceKey="RelatieHeaderLabel">Selecteer een relatie</asp:Label>
                </td>
                <td>
                    <asp:Label ID="ActiveRelatieHeaderLabel" runat="server"  meta:ResourceKey="ActiveRelatieHeaderLabel">Gekoppelde relaties voor geslecteerde artikelgroep</asp:Label>
                </td>
            </tr>
            <tr>
                <td valign="top">        
                    <telerik:RadComboBox ID="RelatiesCbx" runat="server" AppendDataBoundItems="true" AutoPostBack="true">
                        <Items>
                            <telerik:RadComboBoxItem Text=" Selecteer " Value="-1" />
                        </Items>
                    </telerik:RadComboBox>
                </td>
                <td>
                    <asp:TextBox ID="ActiveRelatiesText" runat="server" Rows="1" Columns="60" TextMode="MultiLine" ReadOnly="true"
                        onfocus="ChangeRows();" onblur="this.rows='1';"></asp:TextBox>
                    <asp:HiddenField ID="RowText" runat="server" Value="90" />
                </td>
            </tr>
        </table>
    </div>
  
<telerik:RadListView ID="GroepenLvw" runat="server" AllowPaging="True" ItemPlaceholderID="GroepItemContainer">
    <LayoutTemplate>
        <fieldset style="width: 700px;">
            <legend>Artikelgroepen</legend>
            <table cellpadding="0" cellspacing="0" style="width: 700px;">
                <tr>
                    <td>
                        <asp:Panel ID="GroepItemContainer" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <telerik:RadDataPager ID="GroepPager" runat="server" PagedControlID="GroepenLvw"
                            PageSize="6">
                            <Fields>
                                <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
                                <telerik:RadDataPagerButtonField FieldType="Numeric" />
                                <telerik:RadDataPagerButtonField FieldType="NextLast" />
                            </Fields>
                        </telerik:RadDataPager>
                    </td>
                </tr>
            </table>
        </fieldset>
    </LayoutTemplate>
    <ItemTemplate>
        <fieldset style="float: left; width: 226px; height: 200px;">
            <table cellpadding="2" cellspacing="0" style="height: 100%;">
                <tr>
                    <td style="width: 20%;">
                        <asp:label ID="MenuTekstLabel" runat="server">Headertekst</asp:label>            
                    </td>
                    <td style="width: 80%; padding-left: 5px;">
                        <asp:Label ID="NormalTekstText" runat="server" Text='<%# Eval("strNormalTekst") %>'></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:label ID="MenuIconLabel" runat="server">Menu icoon</asp:label>                        
                    </td>
                    <td style="width: 80%; padding-left: 5px;">
                        <telerik:RadBinaryImage id="IconRbi" runat="server" AutoAdjustImageControlSize="true" ResizeMode="None" ImageAlign="Middle" BorderWidth="0" 
                                        ImageUrl='<%# ResolveUrl(String.Concat("~/MenuIcons/",App.Configuration.MenuIconHeight, "x", App.Configuration.MenuIconWidth, ".", Eval("StrIconPath"))) %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:label ID="MenuvoettekstLabel" runat="server">Menu voettekst</asp:label>
                    </td>
                    <td style="width: 80%; padding-left: 5px;">
                        <asp:label ID="DetailTekstText" runat="server" Text='<%# Eval("StrDetailTekst") %>' ></asp:label>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:ImageButton ID="Button1" runat="server" CommandName="Edit" ImageUrl="~/Images/Editor.png" />
                    </td>
                </tr>
            </table>
        </fieldset>
    </ItemTemplate
    <EditItemTemplate>
        <fieldset style="float: left; width: 226px; height: 240px;">
            <table cellpadding="2" cellspacing="0" style="height: 100%;">
                <tr>
                    <td style="width: 20%;">
                        <asp:label ID="MenuTekstLabel" runat="server">Headertekst</asp:label>            
                    </td>
                    <td style="width: 80%; padding-left: 5px;">
                        <asp:TextBox ID="NormalTekstText" runat="server" Text='<%# Bind("strNormalTekst") %>' width="75%"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:label ID="MenuIconLabel" runat="server">Menu icoon</asp:label>                        
                    </td>
                    <td style="width: 80%; padding-left: 5px;">
                        <asp:TextBox ID="ImagePathText"  runat="server" Text='<%# Bind("StrIconPath") %>' ></asp:TextBox
                        <asp:Button ID="PreviewImage" runat="server" text="Browse" CssClass="art-button" OnClientClick="OpenFileExplorerDialog(); return false;" />
                        <telerik:RadBinaryImage id="IconRbi" runat="server" AutoAdjustImageControlSize="true" ResizeMode="None" ImageAlign="Middle" BorderWidth="0" 
                                        ImageUrl='<%# ResolveUrl(String.Concat("~/MenuIcons/",App.Configuration.MenuIconHeight, "x", App.Configuration.MenuIconWidth, ".", Eval("StrIconPath"))) %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:label ID="MenuvoettekstLabel" runat="server">Menu voettekst</asp:label>
                    </td>
                    <td style="width: 80%; padding-left: 5px;">
                                    <telerik:RadEditor ID="DetailTekstText" runat="server"
                                        EditModes="Html"
                                        ToolbarMode="ShowOnFocus"
                                        AutoResizeHeight="false"
                                        Height="150px"
                                        Width="98%"
                                        ToolsWidth="200px"
                                        Content='<%# Bind("StrDetailTekst") %>'>
                                    </telerik:RadEditor>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:ImageButton ID="Button1" runat="server" CommandName="Update" Text="Update" ImageUrl="~/Imgages/Update.gif" />
                        <asp:ImageButton ID="Button2" runat="server" CommandName="Cancel" Text="Cancel" ImageUrl="~/Imgages/Cancel.gif" />
                    </td>
                </tr>
            </table>
        </fieldset>
    </EditItemTemplate
</telerik:RadListView>
  
  
<telerik:RadGrid ID="GroepGrid" runat="server" AllowPaging="True" PageSize="2"
        AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" GridLines="None"></telerik:RadGrid>
  
  
  
  
    </div>
    </form>
</body>
</html>

CODEBEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Drumis.ECommerce.WebLibrary.Bases;
using Drumis.ECommerce.Model;
using Drumis.Licentie.Configuration;
  
namespace Drumis.ECommerce.Website.Admin.Content
{
    public partial class Artikelgroepen : BasePage
    {
        [Serializable()]
        public class ArtikelGroepItem
        {
            int _iDArtikelGroep;
            int _iDArtikelGroepTekst;
            string _strDetailTekst;
            string _strGeneralTekst;
            string _strIconPath;
            string _strLocaleId;
            string _strNormalTekst;
  
            public ArtikelGroepItem(TblCSArtikelGroepTeksten item)
            {
                _iDArtikelGroep = item.IDArtikelGroep;
                _iDArtikelGroepTekst = item.IDArtikelGroepTekst;
                _strDetailTekst = item.StrDetailTekst;
                _strGeneralTekst = item.StrGeneralTekst;
                _strIconPath = item.StrIconPath;
                _strLocaleId = item.StrLocaleId;
                _strNormalTekst = item.StrNormalTekst;
            }
  
            public int IDArtikelGroep
            {
                get
                {
                    return _iDArtikelGroep;
                }
                set
                {
                    _iDArtikelGroep = value;
                }
            }
  
            public int IDArtikelGroepTekst
            {
                get
                {
                    return _iDArtikelGroepTekst;
                }
                set
                {
                    _iDArtikelGroepTekst = value;
                }
            }
  
            public string StrDetailTekst
            {
                get
                {
                    return _strDetailTekst;
                }
                set
                {
                    _strDetailTekst = value;
                }
            }
  
            public string StrGeneralTekst
            {
                get
                {
                    return _strGeneralTekst;
                }
                set
                {
                    _strGeneralTekst = value;
                }
            }
  
            public string StrIconPath
            {
                get
                {
                    return _strIconPath;
                }
                set
                {
                    _strIconPath = value;
                }
            }
  
            public string StrLocaleId
            {
                get
                {
                    return _strLocaleId;
                }
                set
                {
                    _strLocaleId = value;
                }
            }
  
            public string StrNormalTekst
            {
                get
                {
                    return _strNormalTekst;
                }
                set
                {
                    _strNormalTekst = value;
                }
            }
        }
  
        List<ArtikelGroepItem> GroepItems
        {
            get
            {
                List<int> artikelgroepIds = new List<int>();
                IQueryable<TVWD4WCSArtikelGroepenMultiLingual> col = null;
                if (RelatiesCbx.SelectedValue != "-1")
                {
                    int iOut = 0;
                    int.TryParse(RelatiesCbx.SelectedValue, out iOut);
  
                    List<int> groepenRelatie = context.TVWD4WCSArtikelGroepenPerRelaties.Where(s =>
                                                    s.IDRelatie.Equals(0) || s.IDRelatie.Equals(iOut))
                                                    .Select(s => s.GroupId).ToList();
                                                      
                    artikelgroepIds = context.TVWD4WCSArtikelGroepenMultiLinguals.Where(s => 
                                    (string.IsNullOrEmpty(s.StrLocaleId) || s.StrLocaleId.ToLower().Equals("nl")) 
                                    && groepenRelatie.Contains(s.IDArtikelGroep))
                                    .Select(s => s.IDArtikelGroep).ToList();
                }
                else
                {
                    artikelgroepIds = context.TVWD4WCSArtikelGroepenMultiLinguals.Where(s => 
                                    string.IsNullOrEmpty(s.StrLocaleId) || s.StrLocaleId.ToLower().Equals("nl"))
                                    .Select(s => s.IDArtikelGroep).ToList();
                }
  
                IQueryable<TblCSArtikelGroepTeksten> result = context.TblCSArtikelGroepTekstens.Where(s =>
                                    artikelgroepIds.Contains(s.IDArtikelGroep) && s.StrLocaleId.ToLower().Equals("nl"))
                                    .OrderBy(s => s.StrNormalTekst);
  
                List<ArtikelGroepItem> agResultItems = new List<ArtikelGroepItem>();
                foreach (var item in result)
                {
                    agResultItems.Add(new ArtikelGroepItem(item));
                }
  
                return agResultItems;
            }
        }
  
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            GroepenLvw.NeedDataSource += (s, args) =>
            {
                GroepenLvw.DataSource = GroepItems;
            };
            GroepGrid.NeedDataSource += (s, args) =>
            {
                GroepGrid.DataSource = GroepItems;
            };
        }
  
  
        protected override D4WOptions[] SetValidateOptions()
        {
            return new D4WOptions[] { D4WOptions.X_OPTNR_INTERNET };
        }
    }
}

And the baseclass
public class BasePage : Page
{
    public const string WidthUnit = "px";
    public BasePage();
    public virtual string ContentPanelWidthPixel { get; }
    public D4WData_EntityDiagrams context { get; }
    public InsadD4wUser D4wUser { get; }
    public ErrorDisplay ErrorDisplayCtrl { get; }
    public virtual bool IsHomePage { get; }
    public NavigationMenuItemList menuItemCollection { get; set; }
    public UserControl SidebarInstance { get; }
    public event EventHandler<MessageToDisplayArguments> MessageToDisplay;
    protected void BasePage_MessageToDisplay(object sender, MessageToDisplayArguments e);
    protected override void InitializeCulture();
    protected bool IsNavigation();
    protected override void OnInit(EventArgs e);
    protected void RaiseMessageToDisplay(string message, MessageType type);
    protected override void Render(HtmlTextWriter writer);
    public void SetAjaxReference(Control trigger, Control updated);
    public virtual void SetMessageHandlers();
    public void SetUserLocale();
    public void SetUserLocale(string CurrencySymbol, bool SetUiCulture);
    public void SetUserLocale(string LCID, string CurrencySymbol, bool SetUiCulture);
    protected virtual D4WOptions[] SetValidateOptions();
}

Cheers

3 Answers, 1 is accepted

Sort by
0
Insad
Top achievements
Rank 2
answered on 08 Dec 2010, 09:57 AM
Telerik what is the problem?
Why noone gives a reaction? I even submitted a support ticket wich is open for over 23 hours now...
0
Veli
Telerik team
answered on 08 Dec 2010, 10:21 AM
Hi Insad,

RadListView does not rebind on every postback.  This is why its NeedDataSource event fires once on initial load then does not fire on postback if RadListView does not need to rebind. Rebinding happens automatically if an action that requires rebinding is initiated. You can refer to the RadListView Simple vs Advanced Databinding help topic  that tries to explain the logic behind RadListView's databinding mechanism. I have also attached a test page demonstrating this behavior. RadListView will not rebind on postback, unless you call Rebind() or data operations are performed.

As for the response, note that there is no guaranteed response time from Telerik staff in the forum. You can refer to the Telerik Support Options page for more info and to our Facebook page for getting the best out of Telerik support.

Regards,
Veli
the Telerik team
Browse the vast support resources we have to jumpstart 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.
0
El
Top achievements
Rank 1
answered on 08 Dec 2010, 12:35 PM
You should call its Rebind method if you want to force the ListView to fire NeedDataSource event 
Tags
ListView
Asked by
Insad
Top achievements
Rank 2
Answers by
Insad
Top achievements
Rank 2
Veli
Telerik team
El
Top achievements
Rank 1
Share this question
or