| using System; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Web; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Telerik.Web.UI; |
| |
| public partial class Test_TestProgrammaticRadGrid : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| PopulateGrid(); |
| } |
| |
| private void PopulateGrid() |
| { |
| List<TestData> list = new List<TestData>(); |
| |
| for (int i = 0; i < 11; i++) |
| list.Add(new TestData(i, "test " + i.ToString())); |
| |
| TestRadGrid.DataSource = list; |
| TestRadGrid.DataBind(); |
| } |
| |
| protected void Page_Init(object sender, EventArgs e) |
| { |
| DefineGridStructure(); |
| } |
| |
| private void DefineGridStructure() |
| { |
| TestRadGrid = new RadGrid(); |
| |
| TestRadGrid.AutoGenerateColumns = false; |
| |
| InitializeProblemGrid(TestRadGrid); |
| |
| AddCenteredColumn(TestRadGrid, "ID", "ID", "ID"); |
| AddCenteredColumn(TestRadGrid, "Name", "Name", "Name"); |
| |
| GridPlaceholder.Controls.Add(TestRadGrid); |
| |
| } |
| |
| private void InitializeProblemGrid(RadGrid radGrid) |
| { |
| radGrid.MasterTableView.DataKeyNames = new string[] { "ID" }; |
| radGrid.ClientSettings.Selecting.AllowRowSelect = true; |
| } |
| |
| private void AddCenteredColumn(RadGrid radGrid, string uniqueName, string headerText, string dataField) |
| { |
| GridBoundColumn column = new GridBoundColumn(); |
| column.UniqueName = uniqueName; |
| column.HeaderText = headerText; |
| column.DataField = dataField; |
| column.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; |
| column.ItemStyle.HorizontalAlign = HorizontalAlign.Center; |
| radGrid.MasterTableView.Columns.Add(column); |
| } |
| |
| |
| private RadGrid _TestRadGrid; |
| protected RadGrid TestRadGrid |
| { |
| get { return _TestRadGrid; } |
| set { _TestRadGrid = value; } |
| } |
| |
| } |
| |
| public class TestData |
| { |
| public TestData(int id, string name) |
| { |
| _ID = id; |
| _Name = name; |
| } |
| |
| |
| public int ID |
| { |
| get { return _ID; } |
| set { _ID = value; } |
| } |
| |
| public string Name |
| { |
| get { return _Name; } |
| set { _Name = value; } |
| } |
| |
| |
| private int _ID; |
| private string _Name; |
| } |
| |