This project is read-only.

Grid not showing when data source is empty

Jul 28, 2010 at 1:25 PM
Edited Jul 28, 2010 at 1:26 PM

When the data source is empty (but not null), like an DataTable with no rows, the grid doesn't show and the page gets stuck. The page manager shows simply the loading image.

In the following example, the method FullDataTable doesn't return any rows and the page is therefor not displayed, if the marked row is enabled, the page is displayed appropriately. Attempting to hide the grid doesn't work as well.

 

 

<body>
    <form id="form1" runat="server">
    <ext:PageManager ID="pageManager1" runat="server" />
    <ext:Grid ID="Grid1" runat="server" EnableCheckBoxSelect="true" EnableRowNumber="true"
        Title="Grid">
        <Columns>
            <ext:BoundField ColumnID="r" DataField="Value" />
        </Columns>
    </ext:Grid>
    </form>
</body>

Code behind:

 

 

 protected void Page_Load(object sender, EventArgs e)
        {
            Grid1.DataSource = FullDataTable();
            Grid1.DataBind();
        }

        protected DataTable FullDataTable()
        {
            DataTable newTable = new DataTable();
            newTable.Columns.Add(new DataColumn("Value", typeof(int)));
            DataRow newRow = newTable.NewRow();
            newRow["Value"] = 1;
            //newTable.Rows.Add(newRow); if this row is enabled, the grid shows succesfully.
            return newTable;
        }