I am dynamically creating a RadGrid and adding
After binding datatable to the grid, after user makes changes to the textboxes and on clicking save button, I would like to access the textbox values. But I am stuck at getting hold of the textbox instance. I couldn't even get hold of GridItems!
To add more complexity, my RadGrid is in a UserControl, which is in a (multi)view.
Since my control is in view, it's Page_Init is called more than once for each action that involves this view.
Once the gridstructure is defined, it has no need to change, but I think I should be calling it on Page Init or Load every time..
I have column paging instead of row paging, so there is custom code to handle that.
I would like to get some advice on the best place to call NeedDataSource, DefineGridStructure and where to get Postback values.
I have read this article, but it has sparse information for my need. http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
Heres my code.
GridTemplateColumns to it. Those columns have textbox in them.After binding datatable to the grid, after user makes changes to the textboxes and on clicking save button, I would like to access the textbox values. But I am stuck at getting hold of the textbox instance. I couldn't even get hold of GridItems!
To add more complexity, my RadGrid is in a UserControl, which is in a (multi)view.
Since my control is in view, it's Page_Init is called more than once for each action that involves this view.
Once the gridstructure is defined, it has no need to change, but I think I should be calling it on Page Init or Load every time..
I have column paging instead of row paging, so there is custom code to handle that.
I would like to get some advice on the best place to call NeedDataSource, DefineGridStructure and where to get Postback values.
I have read this article, but it has sparse information for my need. http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
Heres my code.
protected void Page_Init(object sender, EventArgs e) { DefineGridStructure();
}
protected void Page_Load(object sender, EventArgs e)
{
if (RadGrid1 != null && RadGrid1.Items.Count > 0)
{
string strtxt = ((TextBox)RadGrid1.Items[1]["ProductGroup1"].Controls[0]).Text;//For starters, load one control and check it's state
}
}
private void DefineGridStructure() { RadGrid1 = new RadGrid(); RadGrid1.AutoGenerateColumns = false; RadGrid1.ShowHeader = true; RadGrid1.NeedDataSource += RadGrid1_NeedDataSource; foreach(GridColumn qtyColumn in BuildGridQtyColumns(PaxColumnCount)) { RadGrid1.MasterTableView.Columns.Add(qtyColumn); } //Add grid to page phRadGrid.Controls.Add(RadGrid1); } private List<GridColumn> BuildGridQtyColumns(int count) { List<GridColumn> qtyColumns = new List<GridColumn>(); for (int i = 1; i <= count; i++) { string qtyColumnName = string.Format("ProductGroup{0}", i); GridTemplateColumn qtyColumn = new GridTemplateColumn(); qtyColumn.ItemTemplate = new GridNumberTemplate(qtyColumnName);//Creates a textbox control qtyColumn.UniqueName = qtyColumnName; qtyColumn.HeaderText = "Qty"; qtyColumn.HeaderStyle.Width = Unit.Pixel(60); qtyColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; qtyColumns.Add(qtyColumn); } return qtyColumns; }