I have couple of issues related to dynamically created Radgrid.
Background: I have created a dynamic Radgrid which contains Templatecolumn in it, this template columns hold three dropdown list controls which work in a cascading manner. I'm pre-selecting the drop down and for new records its getting default selections. Everything works fine until I get into paging.
Issues: 1. Whenever I use paging the page number is selected in the grid but it always shows first page records.
2. The selections made in previous page dropdown list are not persisting during the paging.
I'm not sure if both are related to same thing. Here is my code for your reference. Your help is highly appreciated.
Background: I have created a dynamic Radgrid which contains Templatecolumn in it, this template columns hold three dropdown list controls which work in a cascading manner. I'm pre-selecting the drop down and for new records its getting default selections. Everything works fine until I get into paging.
Issues: 1. Whenever I use paging the page number is selected in the grid but it always shows first page records.
2. The selections made in previous page dropdown list are not persisting during the paging.
I'm not sure if both are related to same thing. Here is my code for your reference. Your help is highly appreciated.
protected override void OnInit(EventArgs e) { base.OnInit(e); AddGrid(); } private void AddGrid() { _grid = new RadGrid { ID = "TestGrid", PageSize = 30, ShowGroupPanel = false, AllowSorting = false, AllowPaging = true, AutoGenerateColumns = false, GridLines = GridLines.Vertical, VirtualItemCount =0 }; _grid.ClientSettings.AllowDragToGroup = false; _grid.ClientSettings.AllowColumnsReorder = false; _grid.ClientSettings.AllowColumnHide = true; _grid.ClientSettings.Animation.AllowColumnReorderAnimation = false; _grid.ClientSettings.Animation.AllowColumnRevertAnimation = false; _grid.MasterTableView.DataKeyNames = new[] { "Id" }; _grid.MasterTableView.ShowHeadersWhenNoRecords = true; _grid.MasterTableView.UseAllDataFields = true; _grid.MasterTableView.Name = "Master"; _grid.ItemDataBound += GridItemDataBound; _grid.PageIndexChanged += new GridPageChangedEventHandler_grid_PageIndexChanged);_grid.NeedDataSource += new GridNeedDataSourceEventHandler(_grid_NeedDataSource); var countryTemplate= new GridTemplateColumn { UniqueName = "ADDCountry", HeaderText = "Country Field", Resizable = true, }; countryTemplate.HeaderStyle.Font.Bold = true; countryTemplate.ItemTemplate = new Templateclass(countryTemplate.UniqueName, ExcelColumns); _grid.MasterTableView.Columns.Add(sourceTemplate); var stateTemplate = new GridTemplateColumn { UniqueName = "ADDState", HeaderText = "state Column Field", }; stateTemplate .HeaderStyle.Font.Bold = true;stateTemplate .ItemTemplate = new Templateclass(stateTemplate .UniqueName, null); _grid.MasterTableView.Columns.Add(stateTemplate ); var CityTemplate = new GridTemplateColumn { UniqueName = "ADDCity", HeaderText = "Mapping Rule", }; CityTemplate .HeaderStyle.Font.Bold = true; CityTemplate .ItemTemplate = new Templateclass(CityTemplate .HeaderText, null); _grid.MasterTableView.Columns.Add(CityTemplate); Content.Controls.Add(_grid); }void _grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { ((RadGrid)sender).MasterTableView.VirtualItemCount = bindingObject.Count; ((RadGrid)sender).CurrentPageIndex = ((RadGrid)sender).MasterTableView.CurrentPageIndex; ((RadGrid)sender).DataSource = bindingObject; }void _grid_PageIndexChanged(object sender, GridPageChangedEventArgs e) { ((RadGrid)sender).MasterTableView.CurrentPageIndex = ((RadGrid)sender).CurrentPageIndex; } void GridItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem dataItem = (GridDataItem)e.Item; DropDownList ddlCountry= (DropDownList)dataItem.FindControl("ddlCountry"); if (ddlCountry!= null) { ddlCountry.AutoPostBack = true; ddlCountry.SelectedIndexChanged += new EventHandler(ddlCountry_SelectedIndexChanged); } } }public class Templateclass: ITemplate {public Templateclass(string colNames,List<string> CountryNames) { colName = colNames; countryNames= CountryNames; }public void InstantiateIn(Control container) {//create a drop down controls for template columns}