I have the following page:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %><%@ Register Assembly="Infragistics2.WebUI.UltraWebGrid.v7.2, Version=7.2.20072.1063, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server"> <Bands> <igtbl:UltraGridBand> <Columns> <igtbl:UltraGridColumn IsBound="true" BaseColumnName="x"> <Header Caption="Test" /> </igtbl:UltraGridColumn> </Columns> </igtbl:UltraGridBand> </Bands> <DisplayLayout AutoGenerateColumns="false" /> </igtbl:UltraWebGrid> </div> </form></body></html>
and the following code behind:
Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim odtData As New DataTable() odtData.Columns.Add("x", GetType(Integer)) odtData.Rows.Add(0) Me.UltraWebGrid1.DataSource = odtData Me.UltraWebGrid1.DataBind() End If End SubEnd Class
and when I run this I get "No Data to Display". However, when i use a SqlDataSource and add the "DataSourceID" property to the UltraWebGrid tag instead of binding the data in the code behind, it works. If I replace the UltraWebGrid with the basic ASP.NET DataGrid, it works.
Check out the use of DataTable.NewRow in the following example:
Private Sub AddARow(dataSet As DataSet) Dim table As DataTable = dataSet.Tables("Suppliers") ' Use the NewRow method to create a DataRow 'with the table's schema. Dim newRow As DataRow = table.NewRow() ' Set values in the columns: newRow("CompanyID") = "NewCompanyID" newRow("CompanyName") = "NewCompanyName" ' Add the row to the rows collection. table.Rows.Add(newRow)End Sub
I got that from the example at: http://msdn2.microsoft.com/en-us/library/system.data.datatable.rows.aspx
The issue is not how I set up the data. The actual data I am using in the application I am writing is coming from a SQL Server database. I just created a minimal example that demonstrates the issue. Also, like I said, the exact same code behind works If I use an ASP.NET datagrid -- so the issue is with the WebGrid control, not with the DataTable. However, I have tried using DataTable.NewRow() -- it still does not work. Here is the ASPX markup:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %><%@ Register Assembly="Infragistics2.WebUI.UltraWebGrid.v7.2, Version=7.2.20072.1063, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:DataGrid ID="dgTestGrid" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundColumn DataField="x" HeaderText="Test" /> </Columns> </asp:DataGrid> <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server"> <Bands> <igtbl:UltraGridBand> <Columns> <igtbl:UltraGridColumn IsBound="true" BaseColumnName="x"> <Header Caption="Test" /> </igtbl:UltraGridColumn> </Columns> </igtbl:UltraGridBand> </Bands> <DisplayLayout AutoGenerateColumns="false" /> </igtbl:UltraWebGrid> </div> </form></body></html>
And here is the code behind:
Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim odtData As New DataTable() Dim odrRow As DataRow odtData.Columns.Add("x", GetType(Integer)) odrRow = odtData.NewRow() odrRow("x") = 0 odtData.Rows.Add(odrRow) Me.UltraWebGrid1.DataSource = odtData Me.UltraWebGrid1.DataBind() Me.dgTestGrid.DataSource = odtData Me.dgTestGrid.DataBind() End If End SubEnd Class
The ASP.NET datagrid displays a single column with a caption of "Test" and a single row containing "0". The UltraWebGrid displays "No Data To Display".
I did figure out what the problem is, however. In order for the binding to work, the "BaseTableName" property has to be set in the <igtbl:UltraGridBand> tag, and the "TableName" property has to be set on the DataTable. If the TableName property is blank (""), there is no way to do the binding (even setting BaseTableName="" will not cause it to a DataTable with a TableName of "").
I'm still just shooting from the hip, here, but I've never seen a <columns> tag outside a <bands> tag. I don't see anything wrong with your <UltraGridColumn> tag, except that features like column sorting won't work unless it also has a Key="x" property.
HTH
There is no <Columns> tag outside the <Bands> tag.. unless you are referring to the other control, which is an ASP.NET DataGrid control, which doesn't have a <Bands> tag. But your example above had an actual table name ("Suppliers"). That was the main difference I saw between your example and what I had done -- and it makes sense that you would have to map the table to a band somehow, since you can have multiple bands displaying data from multiple tables, whereas the ASP.NET datagrid, in effect, has only one "band", so no mapping is necessary.
bkimmelca said:There is no <Columns> tag outside the <Bands> tag.. unless you are referring to the other control
My bad. Sorry.