Hi,
I'm new to Telerik. Virtually all of the pages I work with are actually user controls, being built entirely dynamically, usually in OnInit. I'm finding it hard to get the Grid (first control I've tried) to behave in this situation. Any client actions performed don't seem to produce the intended result. For instance, Paging just stays on Page 1, Page Size does not take, etc.
You'll notice I'm using the Ajax Panel, but I've tried it without, as well. Thought it might have to do with ViewState/Postback and you can see commented code related to this, but all the permutations I've tried produce the same behavior.
Most of this code was copied and pasted from Telerik demos, primarily the sample at http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section3.
Thanks in advance for your feedback.
JD
I'm new to Telerik. Virtually all of the pages I work with are actually user controls, being built entirely dynamically, usually in OnInit. I'm finding it hard to get the Grid (first control I've tried) to behave in this situation. Any client actions performed don't seem to produce the intended result. For instance, Paging just stays on Page 1, Page Size does not take, etc.
You'll notice I'm using the Ajax Panel, but I've tried it without, as well. Thought it might have to do with ViewState/Postback and you can see commented code related to this, but all the permutations I've tried produce the same behavior.
Most of this code was copied and pasted from Telerik demos, primarily the sample at http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section3.
Thanks in advance for your feedback.
JD
protected void _radGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { //if (Page.IsPostBack) // return; string connString = "trust me, the connection string works;"; _connection = new SqlConnection(); _connection.ConnectionString = connString; // connectionString.ConnectionString; _connection.Open(); using (SqlCommand command = _connection.CreateCommand()) { command.CommandText = "dbo.Adddress_ListByCountry"; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@CountryCode", "FRA"); SqlDataReader reader = command.ExecuteReader(); ((RadGrid)source).DataSource = reader; } } protected void _radGrid1_DataBound(object sender, EventArgs e) { if (_connection.State == ConnectionState.Open) { _connection.Close(); } } protected override void OnInit(EventArgs e) { base.OnInit(e); _radGrid1 = DefineGridStructure(); _radAjaxLoadingPanel = new RadAjaxLoadingPanel(); _radAjaxLoadingPanel.ID = "_radAjaxLoadingPanel"; _radAjaxManager = new RadAjaxManager(); _radAjaxManager.ID = "_radAjaxManager"; _radAjaxManager.DefaultLoadingPanelID = "_radAjaxLoadingPanel"; this.Controls.Add(_radAjaxManager); this.Controls.Add(_radAjaxLoadingPanel); AjaxSetting setting = new AjaxSetting(); AjaxUpdatedControl target = new AjaxUpdatedControl(_radGrid1.ID, _radAjaxLoadingPanel.ID); setting.UpdatedControls.Add(target); setting.AjaxControlID = _radGrid1.ID; _radAjaxManager.AjaxSettings.Add(setting); _gridPanel = new Panel(); _gridPanel.ID = "_gridPanel"; _gridPanel.Controls.Add(_radGrid1); this.Controls.Add(_gridPanel); } private RadGrid DefineGridStructure() { RadGrid radGrid1 = new RadGrid(); radGrid1.Skin = "Default"; radGrid1.Width = Unit.Percentage(100); radGrid1.PageSize = 15; radGrid1.AllowPaging = true; radGrid1.AutoGenerateColumns = false; radGrid1.ID = "_radGrid1"; radGrid1.DataBound += _radGrid1_DataBound; radGrid1.NeedDataSource += _radGrid1_NeedDataSource; radGrid1.AllowPaging = true; //radGrid1.EnableViewState = true; //Add columns GridBoundColumn boundColumn; boundColumn = new GridBoundColumn(); boundColumn.DataField = "AddressId"; boundColumn.HeaderText = "Address ID"; radGrid1.MasterTableView.Columns.Add(boundColumn); boundColumn = new GridBoundColumn(); boundColumn.DataField = "AddressText"; boundColumn.HeaderText = "Address"; radGrid1.MasterTableView.Columns.Add(boundColumn); return radGrid1; }