0

我正在将一堆代码从 vb.net 转换为 c#,但我不太了解 vb.net,所以我遇到了很多问题。

有人可以帮我看看这里有什么问题吗?

protected void GenerateSalaryPunchesTable()
        {
            this.dgvPunchs.Rows.Clear();

            string[] DateRange = this.cboPayPeriods.SelectedItem.Text.ToString().Replace(" ", "").Split('-');

            while (Convert.ToDateTime(DateRange[0]) <= Convert.ToDateTime(DateRange[1]))
            {
                if (Convert.ToDateTime(DateRange[0]).DayOfWeek != DayOfWeek.Saturday & Convert.ToDateTime(DateRange[0]).DayOfWeek != DayOfWeek.Sunday)
                {
                    Infragistics.WebUI.UltraWebGrid.UltraGridRow nRow = new Infragistics.WebUI.UltraWebGrid.UltraGridRow();

                    nRow.Cells.Add();
                    // Date Cell
                    nRow.Cells.Add();
                    // Worked CB
                    nRow.Cells.Add();
                    // Vacation CB
                    nRow.Cells.Add();
                    // Sick CB
                    nRow.Cells.Add();
                    // Holiday CB
                    nRow.Cells.Add();
                    // Error

                    nRow.Key = Convert.ToDateTime(DateRange[0].ToString()).ToShortDateString();
                    nRow.Cells[0].Value = Convert.ToDateTime(DateRange[0].ToString()).ToShortDateString();
                    nRow.Cells[1].Value = 0;
                    nRow.Cells[2].Value = 0;
                    nRow.Cells[3].Value = 0;
                    nRow.Cells[4].Value = 0;
                    nRow.Cells[5].Value = "";

                    this.dgvPunchs.Rows.Add(nRow);
                }

                DateRange[0] = Convert.ToDateTime(DateRange[0]).AddDays(1);
            }

        }

这是它给我的错误:

错误 4 'Infragistics.Web.UI.GridControls.ControlDataRecordCollection.Add(Infragistics.Web.UI.GridControls.ControlDataRecord)' 的最佳重载方法匹配有一些无效参数
错误 5 参数 1:无法从 'Infragistics.WebUI.UltraWebGrid 转换.UltraGridRow' 到 'Infragistics.Web.UI.GridControls.ControlDataRecord'

这是控制:

<ig:WebDataGrid ID="dgvPunchs" runat="server" Height="350px" Width="400px">
                        </ig:WebDataGrid>

它是从 VB.net 和旧版本的 Infragistics 转换而来的。到目前为止,我无法弄清楚这一点。

编辑:

我试过这个,它也没有工作......

Infragistics.Web.UI.GridControls.ControlDataRecord nRow =
  Infragistics.Web.UI.GridControls.ControlDataRecord();
//Infragistics.WebUI.UltraWebGrid.UltraGridRow nRow = new Infragistics.WebUI.UltraWebGrid.UltraGridRow();
4

1 回答 1

1

发生异常是因为您将 UltraGridRow 添加到 WebDataGrid 或 WebHierarchicalDataGrid 的行集合,并且 UltraGridRow 与 UltraWebGrid 一起使用。

由于您更改了正在使用的网格,因此代码不会出现 1:1 映射,因此这会增加转换的复杂性。你最好看看你想要完成什么,然后编写新的网格控件所需的代码。

通常对于数据行,WebDataGrid 使用 GridRecord 对象,您可以测试创建其中一个对象以向网格添加新行。

请注意,从您调用的方法看来,您正在为网格动态创建所有数据,如果是这种情况,那么您最好创建一个 DataTable 并将网格绑定到 DataTable 而不是使用网格直接因为网格被设计为绑定到数据。

于 2012-08-15T01:42:55.043 回答