为什么我的ASPxGridView显示空白行而不是我提供的值?

时间:2018-09-26 15:14:50

标签: c# asp.net devexpress aspxgridview

在描述问题之前,我想说明一下我已在DevEx上提交了故障单,但我也希望从Stack Overflow中获得更快的响应。

问题:

我正在从动态DataTable中填充此ASPxGridView。我遇到的问题是字段为空,但显示的行数正确。调试时,如果进入dataTable.Rows[0].itemArray属性,则可以看到正确的值。在此过程中我可能缺少步骤吗?

下面的代码:

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>

1 个答案:

答案 0 :(得分:2)

  

您忘记在ASPxGridView定义中指定FieldName。   如果出现以下情况,则FieldName必须为数据表列名称或属性名称   收集数据源已分配。

如下修改标记:

<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>