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:
My aspx.cs file
No idea what the problem is.
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.