我正在将一堆代码从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.Web.UI.GridControls.ControlDataRecord nRow =
Infragistics.Web.UI.GridControls.ControlDataRecord();
//Infragistics.WebUI.UltraWebGrid.UltraGridRow nRow = new Infragistics.WebUI.UltraWebGrid.UltraGridRow();发布于 2012-08-15 09:42:55
之所以会发生异常,是因为您向WebDataGrid或WebHierarchicalDataGrid的行集合添加了一个UltraGridRow,而该UltraGridRow与UltraWebGrid一起使用。
由于您已经更改了正在使用的网格,因此代码将不会有1:1的映射,因此这将增加转换的复杂性。你最好先看一看你想要完成什么,然后编写新的网格控件所需的代码。
通常,对于数据行,WebDataGrid使用GridRecord对象,您可以测试创建其中一个对象以向网格添加新行。
请注意,从您调用的方法可以看出,您正在为网格动态创建所有数据,如果是这样的话,您最好创建一个DataTable并将网格绑定到DataTable,而不是直接使用网格,因为网格被设计为绑定到数据。
https://stackoverflow.com/questions/11961823
复制相似问题