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

Unwanted column text added after sort

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 2
George asked on 13 Mar 2015, 09:56 PM
The grid looks fine and when I sort a column the class name of my Serializable class gets added many time to the right.  Every time I press sort more text gets added. I have attached picture.

I am trying to add columns names at runtime since I do not know them in advanced.  My code is based on the Grid - Virtualization example and the documentation on columns Creating a Hierarchical Grid Programmatically.  It basically right out of the example and documentation.

My Asp:
<%@ Page Title="Group Administration" Language="C#" MasterPageFile="~/Organization.Master" AutoEventWireup="true" CodeBehind="GroupAdmin.aspx.cs" Inherits="SignupList.Admin.GroupAdmin" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
 
    Administration
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel"></telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel" LoadingPanelID="RadAjaxLoadingPanel" CssClass="demo-container">   
    <telerik:RadGrid ID="AdminGrid" OnNeedDataSource="AdminGrid_NeedDataSource" runat="server"
        Skin="Default" AutoGenerateColumns="false" AllowSorting="true" GroupingEnabled="false"
            EnableHeaderContextMenu="true" AllowPaging="true" PageSize="50">
 
        <ClientSettings ReorderColumnsOnClient="true" AllowColumnsReorder="true" ColumnsReorderMethod="Reorder">
                <Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="2000"
                    LoadingPanelID="RadAjaxLoadingPanel" ItemsPerView="100"/>
                <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="500px" />
                <Resizing AllowColumnResize="true" />
            </ClientSettings>
            <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
 
    </telerik:RadGrid>
</telerik:RadAjaxPanel>
</asp:Content>

My aspx.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using SignupList.Com.SignupList;
using SignupList.Com.SignupList.Display.Models;
using Telerik.Web.UI;
 
namespace SignupList.Admin
{
    public partial class GroupAdmin : System.Web.UI.Page
    {
        protected void Page_Init(object source, System.EventArgs e)
        {
             DefineGridStructure(AdminGrid);
        }
 
        protected void Page_Load(object sender, EventArgs e) {
        }
 
        private static readonly Random Random = new Random();
         static string[] contactNames = new string[] { "Antonio Moreno", "Elizabeth Lincoln", "Hanna Moos", "Jaime Yorres", "Georg Pipps",
        "Pascale Cartrain", "Paul Henriot", "Matti Karttunen", "Patricio Simpson","Howard Snyder"};
        static string[] companyNames = new string[] { "Blauer See Delikatessen", "Folies gourmandes", "Hungry Coyote Import Store", "Let's Stop N Shop",
            "B's Beverages", "QUICK-Stop", "Split Rail Beer & Ale", "Wartian Herkku","Sant� Gourmet","Romero y tomillo" };
        static string[] contactTitles = new string[] { "Marketing Assistant", "Sales Associate", "Sales Agent", "Sales Representative",
            "Owner", "Sales Manager", "Accounting Manager","Marketing Manager","Sales Consultant","Accountant"};
        static string[] countries = new string[] { "Bulgaria", "USA", "Austria", "Germany", "Italy", "England", "Argentina", "Brazil", "France", "Spain" };
        static string[] ratings = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
 
        public List<Member> DataSource
        {
            get
            {
                object obj = Application["GroupAdminDataSource"];
                if (obj == null) {
                    List<Member> customers = new List<Member>();
                    for (int i = 0; i < 2000; i++)
                    {
                        int titlesIndex = Random.Next() % 10;
                        int companyIndex = Random.Next() % 10;
                        int contactIndex = Random.Next() % 10;
                        int ratingIndex = Random.Next() % 10;
                        int countryIndex = Random.Next() % 10;
                        Member customer = new Member();
                        customer.ID = (i + 1).ToString();
;
                        customer.Value1 = contactTitles[titlesIndex];
                        customer.Value2 = companyNames[companyIndex];
                        customer.Value3 = contactNames[contactIndex];
                        customer.Value4 = countries[countryIndex];
                        customer.Value5 = ratings[ratingIndex];
                        customers.Add(customer);
                    }
                    Application["GroupAdminDataSource"] = customers;
                }
                return (List<Member>)Application["GroupAdminDataSource"];
            }
            set
            {
                Application["GroupAdminDataSource"] = value;
            }
        }
 
       protected void AdminGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            AdminGrid.DataSource = DataSource;
        }
 
        [Serializable]
        public class Member
        {
            public string ID { get; set; }
            public string Value1 { get; set; }
            public string Value2 { get; set; }
            public string Value3 { get; set; }
            public string Value4 { get; set; }
            public string Value5 { get; set; }
        }
 
        private void DefineGridStructure(RadGrid adminGrid)
        {
            if (adminGrid.MasterTableView.Columns.Count > 1) {
                // exit if columns are already defined
                return;
            }
               
            adminGrid.MasterTableView.DataKeyNames = new string[] { "ID", "Value1", "Value2","Value3", "Value4", "Value5" };
 
            //Add columns
            GridBoundColumn boundColumn;
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "ID";
            boundColumn.DataField = "ID";
            boundColumn.HeaderText = "ID";
            boundColumn.HeaderStyle.Width = Unit.Pixel(50);
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value1";
            boundColumn.DataField = "Value1";
            boundColumn.HeaderText = "Full Name";
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value2";
            boundColumn.DataField = "Value2";
            boundColumn.HeaderText = "Display Name" ;
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value3";
            boundColumn.DataField = "Value3";
            boundColumn.HeaderText = "Email";
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value4";
            boundColumn.DataField = "Value4";
            boundColumn.HeaderText = "Commitment";
            adminGrid.MasterTableView.Columns.Add(boundColumn);          
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value5";
            boundColumn.DataField = "Value5";
            boundColumn.HeaderText = "Hours";
            boundColumn.HeaderStyle.Width = Unit.Pixel(50);
            adminGrid.MasterTableView.Columns.Add(boundColumn);          
 
        }
 
    }
}

No idea what the problem is.

1 Answer, 1 is accepted

Sort by
0
George
Top achievements
Rank 2
answered on 14 Mar 2015, 03:36 AM
I figured out you cannot mix the server column creating with a control existing in the page.  I changed it to create the grid control on the server and everything is working fine.  My serialize class goes up to value 20 and just show the columns that get added.  This will give full control over the number of columns, the column header and the data put into each row and column - this all I need to get it all working.

Here is code if you are interested.    The aspx is now just an empty file with a panel with an id of RadAjaxPanel.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using SignupList.Com.SignupList;
using SignupList.Com.SignupList.Display.Models;
using Telerik.Web.UI;
 
namespace SignupList.Admin
{
    public partial class GroupAdmin : System.Web.UI.Page
    {
        protected void Page_Init(object source, System.EventArgs e)
        {
            RadGrid adminGrid = new RadGrid();
            adminGrid.DataSource = DataSource;
             
            adminGrid.Skin = "Default";
            adminGrid.AutoGenerateColumns = false;
            adminGrid.AllowSorting = true;
            adminGrid.GroupingEnabled = false;
            adminGrid.EnableHeaderContextMenu = true;
            adminGrid.AllowPaging = true;
            adminGrid.PageSize = 500;
            adminGrid.Height = Unit.Percentage(100);
            adminGrid.AllowFilteringByColumn = true;
                        
            adminGrid.ClientSettings.ReorderColumnsOnClient = true;
            adminGrid.ClientSettings.AllowColumnsReorder = true;
            adminGrid.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Reorder;
            adminGrid.ClientSettings.Virtualization.EnableVirtualization = true;
            adminGrid.ClientSettings.Virtualization.InitiallyCachedItemsCount = 2000;
            adminGrid.ClientSettings.Scrolling.AllowScroll = true;
            adminGrid.ClientSettings.Scrolling.UseStaticHeaders = true;
            adminGrid.ClientSettings.Scrolling.ScrollHeight = Unit.Percentage(100);
            adminGrid.ClientSettings.Resizing.AllowColumnResize = true;
            adminGrid.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
             
            //Add columns
            GridBoundColumn boundColumn;
            GridNumericColumn numericColumn;
 
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "ID";
            boundColumn.DataField = "ID";
            boundColumn.HeaderText = "ID";
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value1";
            boundColumn.DataField = "Value1";
            boundColumn.HeaderText = "Full Name";
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value2";
            boundColumn.DataField = "Value2";
            boundColumn.HeaderText = "Display Name" ;
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value3";
            boundColumn.DataField = "Value3";
            boundColumn.HeaderText = "Email";
            adminGrid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.UniqueName = "Value4";
            boundColumn.DataField = "Value4";
            boundColumn.HeaderText = "Commitment";
            adminGrid.MasterTableView.Columns.Add(boundColumn);          
            numericColumn = new  GridNumericColumn();
            numericColumn.UniqueName = "Integer0";
            numericColumn.DataField = "Integer0";
            numericColumn.HeaderText = "Hours";
            numericColumn.NumericType = NumericType.Number;
            numericColumn.HeaderStyle.Width = Unit.Pixel(90);
            numericColumn.FilterControlWidth = Unit.Pixel(50);
            adminGrid.MasterTableView.Columns.Add(numericColumn);          
 
            this.RadAjaxPanel.Controls.Add(adminGrid);
 
        }
 
        protected void Page_Load(object sender, EventArgs e) {
        }
 
        private static readonly Random Random = new Random();
         static string[] contactNames = new string[] { "Antonio Moreno", "Elizabeth Lincoln", "Hanna Moos", "Jaime Yorres", "Georg Pipps",
        "Pascale Cartrain", "Paul Henriot", "Matti Karttunen", "Patricio Simpson","Howard Snyder"};
        static string[] companyNames = new string[] { "Blauer See Delikatessen", "Folies gourmandes", "Hungry Coyote Import Store", "Let's Stop N Shop",
            "B's Beverages", "QUICK-Stop", "Split Rail Beer & Ale", "Wartian Herkku","Sant� Gourmet","Romero y tomillo" };
        static string[] contactTitles = new string[] { "Marketing Assistant", "Sales Associate", "Sales Agent", "Sales Representative",
            "Owner", "Sales Manager", "Accounting Manager","Marketing Manager","Sales Consultant","Accountant"};
        static string[] countries = new string[] { "Bulgaria", "USA", "Austria", "Germany", "Italy", "England", "Argentina", "Brazil", "France", "Spain" };
        static int[] ratings = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
        public List<Member> DataSource
        {
            get
            {
                object obj = Application["GroupAdminDataSource"];
                if (obj == null) {
                    List<Member> customers = new List<Member>();
                    for (int i = 0; i < 2000; i++)
                    {
                        int titlesIndex = Random.Next() % 10;
                        int companyIndex = Random.Next() % 10;
                        int contactIndex = Random.Next() % 10;
                        int ratingIndex = Random.Next() % 10;
                        int countryIndex = Random.Next() % 10;
                        Member member = new Member();
                        member.ID = (i + 1).ToString();
;
                        member.SetValue(1, contactTitles[titlesIndex]);
                        member.SetValue(2, companyNames[companyIndex]);
                        member.SetValue(3, contactNames[contactIndex]);
                        member.SetValue(4, countries[countryIndex]);
                        member.SetInteger(0, ratings[ratingIndex]);
 
                        customers.Add(member);
                    }
                    Application["GroupAdminDataSource"] = customers;
                }
                return (List<Member>)Application["GroupAdminDataSource"];
            }
            set
            {
                Application["GroupAdminDataSource"] = value;
            }
        }
 
 
        [Serializable]
        public class Member
        {
            public string ID { get; set; }
            public string Value0 { get; set; }
            public string Value1 { get; set; }
            public string Value2 { get; set; }
            public string Value3 { get; set; }
            public string Value4 { get; set; }
            public string Value5 { get; set; }
            public string Value6 { get; set; }
            public string Value7 { get; set; }
            public string Value8 { get; set; }
            public string Value9 { get; set; }
            public string Value10 { get; set; }
            public string Value11 { get; set; }
            public string Value12 { get; set; }
            public string Value13 { get; set; }
            public string Value14 { get; set; }
            public string Value15 { get; set; }
            public double Number0 { get; set; }
            public double Number1 { get; set; }
            public double Number2 { get; set; }
            public double Number3 { get; set; }
            public double Number4 { get; set; }
            public double Number5 { get; set; }
            public int Integer0 { get; set; }
            public int Integer1 { get; set; }
            public int Integer2 { get; set; }
            public int Integer3 { get; set; }
            public int Integer4 { get; set; }
            public int Integer5 { get; set; }
 
 
            public string SetValue(int num, string value)
            {
                switch(num) {
                    case 0:
                        Value0 = value;
                        break;
                    case 1:
                        Value1 = value;
                        break;
                    case 2:
                        Value2 = value;
                         break;
                    case 3:
                       Value3 = value;
                        break;
                    case 4:
                        Value4 = value;
                        break;

George
Tags
Grid
Asked by
George
Top achievements
Rank 2
Answers by
George
Top achievements
Rank 2
Share this question
or