Example:
<trirand:JQGrid ID="DataTableGrid" runat="server"></trirand:JQGrid>
protected DataTable GetDataTableWithSchema() { DataTable dt = new DataTable(); dt.Columns.Add("id"); dt.Columns.Add("invdate"); dt.Columns.Add("name", typeof(int)); dt.Columns.Add("amount", typeof(double)); dt.Columns.Add("tax"); dt.Columns.Add("total"); dt.Columns.Add("note"); return dt; } protected DataTable GetData() { Random r = new Random(System.DateTime.Now.Millisecond); DataTable dt = GetDataTableWithSchema(); for (int i = 0; i < 100; i++) { dt.Rows.Add(new object[] { "a" + i.ToString(), "a", i, Convert.ToDouble(i), "a", "a", "a" }); } return dt; } protected void Page_Load(object sender, EventArgs e) { DataTableGrid.DataSource = GetData(); DataTableGrid.DataBind(); }
If you are using DataSets instead of DataTable, then you can have multiple DataTables in the same DataSets. Therefore you may also need to specify the name of the DataTable to use - this can be done by using the DataMember property of the grid. If DataMember is not specified, jqGrid will use the first DataTable in the DataSet.