I would like to know what is the most barebones way to just say bind data to an UltraWebGrid that is created in code-behind. E.g like below. Problem with my code below is it always says no data to display.
Anyone?
using System;using System.Data;using Infragistics.WebUI.UltraWebGrid;namespace StarTestArea{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { CreateGrid(); BindData(); } private void CreateGrid() { grid1 = new UltraWebGrid(); grid1.DisplayLayout.AutoGenerateColumns = true; form1.Controls.Add(grid1); } private void BindData() { DataTable dataTable = new DataTable("Customers"); DataColumn colWork = new DataColumn("CustomerID", Type.GetType("System.Int32")); dataTable.Columns.Add(colWork); DataColumn[] keys = { colWork }; dataTable.PrimaryKey = keys; colWork = new DataColumn("CustomerName", Type.GetType("System.String")); colWork.MaxLength = 50; dataTable.Columns.Add(colWork); colWork = new DataColumn("LastOrderDate", Type.GetType("System.DateTime")); dataTable.Columns.Add(colWork); DataRow row = dataTable.NewRow(); row["CustomerID"] = 1; row["CustomerName"] = "John's Widgets"; row["LastOrderDate"] = DateTime.Now; dataTable.Rows.Add(row); row = dataTable.NewRow(); row["CustomerID"] = 2; row["CustomerName"] = "Fred's Thingamagigs"; row["LastOrderDate"] = DateTime.Now.AddDays(-101); dataTable.Rows.Add(row); grid1.DataSource = dataTable; grid1.DataBind(); } private UltraWebGrid grid1; }}
Make sure you set the ID property of your grid.
Otherwise, nothing else jumps out at me, having not yet tested it. This should likely work.
Depending on what events you may want to use in the grid down the line, you might want to move your call to CreateGrid() into the Page_Init event, rather than Page_Load.