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

Serious bug: programatically added columns and postback!

1 Answer 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
EB
Top achievements
Rank 1
EB asked on 08 Sep 2008, 10:12 AM
Hi all,

I'm using latest RadGrid (build 2008.2.826.35).

Problem with this code: Extra columns (no header text) keep adding at every post-back!!! even I call the Clear() method of the Columns collection. That doesn't do anything.

By putting the DefineGridStructure() method in Page_Load, instead of Page_Init, everytime the page is posted back, all column header texts and link buttons disappear.

ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="ING.MasterFund.RoadRunner.Web.Default2" %> 
 
<%@ 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"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
    <asp:PlaceHolder ID="PlaceHolder1" runat="server" /> 
    <br /> 
    <asp:Button ID="_postBackButton" runat="server" Text="Post Back" /> 
    </form> 
</body> 
</html> 
 

Code-Behind:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web.UI; 
using Telerik.Web.UI; 
 
namespace ING.MasterFund.RoadRunner.Web 
    public partial class Default2 : Page 
    { 
        public class Customer 
        { 
            public string ID { getset; } 
            public string Name { getset; } 
        } 
 
        protected void Page_Init( object sender, EventArgs e ) 
        { 
            DefineGridStructure(); 
        } 
 
        protected void Page_Load( object sender, EventArgs e ) 
        { 
            if ( !IsPostBack ) 
            { 
                List<Customer> customers = new List<Customer> 
                                               { 
                                                       new Customer {ID = "0", Name = "John"}, 
                                                       new Customer {ID = "1", Name = "Peter"}, 
                                                       new Customer {ID = "2", Name = "Heo"
                                               }; 
                RadGrid grid = (RadGrid) PlaceHolder1.Controls[0]; 
                grid.DataSource = customers; 
                grid.DataBind(); 
            } 
        } 
 
        protected void DefineGridStructure() 
        { 
            RadGrid grid = new RadGrid(); 
            PlaceHolder1.Controls.Add(grid); 
 
            grid.AutoGenerateColumns = false
            grid.MasterTableView.Columns.Clear(); 
            grid.MasterTableView.Columns.Add(new GridBoundColumn {DataField = "ID", HeaderText = "ID"}); 
            grid.MasterTableView.Columns.Add(new GridBoundColumn {DataField = "Name", HeaderText = "Name"}); 
            grid.MasterTableView.Columns.Add(new GridButtonColumn {ButtonType = GridButtonColumnType.LinkButton, HeaderText = "Action", Text = "click"}); 
        } 
    } 

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 Sep 2008, 10:25 AM
Tags
Grid
Asked by
EB
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or