Hello,
I have added RadGrid on ASPX page and I want to add columns dynamically to this RadGrid.
I am facing problem like if page gets refreshed it creates some extra columns at the end. It should maintain same columns if i sort/change page or any postback occurs because of asp.net controls.
Here is the code that I am using.
I have added RadGrid on ASPX page and I want to add columns dynamically to this RadGrid.
I am facing problem like if page gets refreshed it creates some extra columns at the end. It should maintain same columns if i sort/change page or any postback occurs because of asp.net controls.
Here is the code that I am using.
ZZZ.BL.ReportsBL reportBl = newZZZ.BL.ReportsBL(); protected void Page_Init(object source, System.EventArgs e) { RadGrid1.MasterTableView.Columns.Clear(); BuildGridColumns(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { drpBillingCycles.DataSource = reportBl.GetBillingCycles(37); drpBillingCycles.DataBind(); } } protected void drpBillingCycles_SelectedIndexChanged(object sender, EventArgs e) { int PageCount = 0; System.Data.DataTable cd = new System.Data.DataTable(); RadGrid1.VirtualItemCount = PageCount; RadGrid1.DataSource = reportBl.GetReportData("325012", 37, RadGrid1.CurrentPageIndex, RadGrid1.PageSize, out PageCount); RadGrid1.DataBind(); } protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { int PageCount = 0; RadGrid1.VirtualItemCount = PageCount; RadGrid1.DataSource = reportBl.("325012", 37, RadGrid1.CurrentPageIndex, RadGrid1.PageSize, out PageCount); //RadGrid1.DataBind(); } private void BuildGridColumns() { RadGrid1.MasterTableView.Columns.Add(GetGridBoundColumn("PhoneNumber","Phone Number")); RadGrid1.MasterTableView.Columns.Add(GetGridBoundColumn("UserName", "Phone User Name")); RadGrid1.MasterTableView.Columns.Add(GetGridBoundColumn("EmpId", "Employee Id")); RadGrid1.MasterTableView.Columns.Add(GetGridBoundColumn("Department", "Radio Number")); } private GridBoundColumn GetGridBoundColumn(string DataField,string HeaderText) { GridBoundColumn boundColumn1 = new GridBoundColumn(); boundColumn1.DataField = DataField; boundColumn1.UniqueName = DataField; boundColumn1.SortExpression = DataField; boundColumn1.HeaderText = HeaderText; return boundColumn1; }