Search code examples
c#asp.netdevexpressaspxgridview

Why is my ASPxGridView showing blank rows instead of the values I am supplying it?


Before the description of the problem, I want to state that I have submitted a ticket on DevEx but I also hope to get a faster response out of Stack Overflow.

The Problem:

I am populating this ASPxGridView from a dynamic DataTable. The problem I am running into is that the fields are blank but the correct number of rows show. When debugging I can see the correct values if I go into dataTable.Rows[0].itemArray property. Is there a step that I'm possibly missing in this process?

Code Below:

void BuildEmployeeTable ()
    {
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("Employee");
        dataTable.Columns.Add("Pending");
        dataTable.Columns.Add("Investigating");
        dataTable.Columns.Add("Assigned");
        dataTable.Columns.Add("CompletedA");
        dataTable.Columns.Add("CompletedS");
        dataTable.Columns.Add("PastDueA");
        dataTable.Columns.Add("PastDueS");
        dataTable.Columns.Add("NotAccepted");

        kaizenSet.EMPLOYEEDataTable dt = GetEmployees();

        foreach (DataRow dr in dt)
        {
            string name = Security.FormatName(dr["NAME"].ToString());
            DataRow new_row = dataTable.NewRow();

            new_row["Employee"] = name;
            new_row["Pending"] = Kaizen_Queries.SubmittedKaizens(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), new DateTime(DateTime.Today.Year, DateTime.Today.Month + 1, 1), name);
            new_row["Investigating"] = Kaizen_Queries.InvestigatingKaizens(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), new DateTime(DateTime.Today.Year, DateTime.Today.Month + 1, 1), name);
            new_row["Assigned"] = Kaizen_Queries.InProgressKaizens(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), new DateTime(DateTime.Today.Year, DateTime.Today.Month + 1, 1), name);
            new_row["CompletedA"] = 0;
            new_row["CompletedS"] = Kaizen_Queries.CompletedKaizens(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), new DateTime(DateTime.Today.Year, DateTime.Today.Month + 1, 1), name);
            new_row["PastDueS"] = Kaizen_Queries.PastDueKaizens(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), new DateTime(DateTime.Today.Year, DateTime.Today.Month + 1, 1), name);
            new_row["PastDueA"] = 0;
            new_row["NotAccepted"] = Kaizen_Queries.NotAcceptedKaizens(new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1), new DateTime(DateTime.Today.Year, DateTime.Today.Month + 1, 1), name);

            dataTable.Rows.Add(new_row);
        }

        gridEmployees.DataSource = dataTable;
        gridEmployees.DataBind();
    }

GridView:

<dx:ASPxGridView ID="gridEmployees" runat="server" AutoGenerateColumns="False" OnLoad="gridEmployees_Load" Width="100%">
            <SettingsAdaptivity>
            <AdaptiveDetailLayoutProperties ColCount="1"></AdaptiveDetailLayoutProperties>
            </SettingsAdaptivity>

            <EditFormLayoutProperties ColCount="1"></EditFormLayoutProperties>
            <Columns>
                <dx:GridViewDataTextColumn Name="Name" Caption="Name" VisibleIndex="0">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="Pending" Caption="Pending" VisibleIndex="1">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="Investigating" Caption="Investigating" VisibleIndex="2">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="Assigned" Caption="Assigned" VisibleIndex="3">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="CompleteA" Caption="Complete (Assigned)" VisibleIndex="4">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="CompleteS" Caption="Complete (Submitted)" VisibleIndex="5">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="PastDueA" Caption="Past Due (Assigned)" VisibleIndex="6">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="PastDueS" Caption="Past Due (Submitted)" VisibleIndex="7">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn Name="NotAccepted" Caption="Not Accepted" VisibleIndex="8">
                </dx:GridViewDataTextColumn>
            </Columns>
        </dx:ASPxGridView>

Solution

  • You forgot to specify the FieldName in the ASPxGridView definition. The FieldName must be the datatable column name or Property name if collection datasource is assigned.

    Modify the markup as below:

    <dx:ASPxGridView ID="gridEmployees" runat="server" AutoGenerateColumns="False" OnLoad="gridEmployees_Load" Width="100%">
        <SettingsAdaptivity>
        <AdaptiveDetailLayoutProperties ColCount="1"></AdaptiveDetailLayoutProperties>
        </SettingsAdaptivity>
    
        <EditFormLayoutProperties ColCount="1"></EditFormLayoutProperties>
        <Columns>
            <dx:GridViewDataTextColumn Name="Name" FieldName="Employee" Caption="Name" VisibleIndex="0">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="Pending" FieldName="Pending" Caption="Pending" VisibleIndex="1">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="Investigating" FieldName="Investigating" Caption="Investigating" VisibleIndex="2">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="Assigned" FieldName="Assigned" Caption="Assigned" VisibleIndex="3">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="CompleteA" FieldName="CompleteA" Caption="Complete (Assigned)" VisibleIndex="4">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="CompleteS" FieldName="CompleteS" Caption="Complete (Submitted)" VisibleIndex="5">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="PastDueA" FieldName="PastDueA" Caption="Past Due (Assigned)" VisibleIndex="6">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="PastDueS" FieldName="PastDueS" Caption="Past Due (Submitted)" VisibleIndex="7">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Name="NotAccepted" FieldName="NotAccepted"  Caption="Not Accepted" VisibleIndex="8">
            </dx:GridViewDataTextColumn>
        </Columns>
    </dx:ASPxGridView>