首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数1:无法从'Infragistics.WebUI.UltraWebGrid.UltraGridRow‘转换为'Infragistics.Web.UI.GridControls.ControlDataRecord’

参数1:无法从'Infragistics.WebUI.UltraWebGrid.UltraGridRow‘转换为'Infragistics.Web.UI.GridControls.ControlDataRecord’
EN

Stack Overflow用户
提问于 2012-08-15 06:36:25
回答 1查看 2.5K关注 0票数 0

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

有人能帮我看看这里出了什么问题吗?

代码语言:javascript
复制
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’

下面是控件:

代码语言:javascript
复制
<ig:WebDataGrid ID="dgvPunchs" runat="server" Height="350px" Width="400px">
                        </ig:WebDataGrid>

它是从VB.net和旧版本的信息收集系统转换而来的。到目前为止我还不能弄明白这一点。

编辑:

我试过了,也不起作用...

代码语言:javascript
复制
Infragistics.Web.UI.GridControls.ControlDataRecord nRow =
  Infragistics.Web.UI.GridControls.ControlDataRecord();
//Infragistics.WebUI.UltraWebGrid.UltraGridRow nRow = new Infragistics.WebUI.UltraWebGrid.UltraGridRow();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-15 09:42:55

之所以会发生异常,是因为您向WebDataGrid或WebHierarchicalDataGrid的行集合添加了一个UltraGridRow,而该UltraGridRow与UltraWebGrid一起使用。

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

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11961823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档