无法将类型为“System.Web.UI.WebControls.ListItem”的对象强制转换为“System.IConvertible”类型

时间:2016-08-26 08:01:24

标签: c#

我正面对这个但无法解决它。这来自List。遇到问题 AddOnTriggerItems = gvTriggerProduct.Rows.Cast<GridViewRow>().Select(rowItem => new AddOnTriggerItem()

ProjectA.TEST.BE.AddOn addOn = new ProjectA.TEST.BE.AddOn()
{    
    AddCode = addCode,          
    CreatedTime = DateTime.Now,
    ModifiedTime = DateTime.Now,
    AddOnTriggers = gvTriggerProduct.Rows.Cast<GridViewRow>().Select(row => new AddOnTrigger()
    {
        AddOnTriggerItems = gvTriggerProduct.Rows.Cast<GridViewRow>().Select(rowItem => new AddOnTriggerItem()
        {
            ProductTypeID = gvTriggerProduct.Rows[rowItem.RowIndex].Cells[1].Text.ToString(),
            ProductCode = gvTriggerProduct.Rows[rowItem.RowIndex].Cells[2].Text.ToString(),     
            CreatedTime = DateTime.Now,
            ModifiedTime = DateTime.Now
        }).ToList(),
        ActiveStatus = 1,
        CreatedTime = DateTime.Now,
        ModifiedTime = DateTime.Now
    }).ToList(),
    AddOnProducts = gvAddOnProduct.Rows.Cast<GridViewRow>().Select(rowAddOnProducts => new AddOnProduct()
    {
        ProductTypeID = gvAddOnProduct.Rows[rowItem.RowIndex].Cells[2].Text.ToString(), 
        ProductCode = gvAddOnProduct.Rows[rowItem.RowIndex].Cells[2].Text.ToString(),   
        CreatedTime = DateTime.Now,
        ModifiedTime = DateTime.Now,
        AddOnProductAllotments = addOnProductAllotmentSession.Where(p => (p.ProductID == (Convert.ToString(((HiddenField)rowAddOnProducts.FindControl("ProductID")).Value)))).ToList(),      
    }).ToList()
};

1 个答案:

答案 0 :(得分:-1)

谢谢grek和derloopkat。 Grek的提示:问题可以在语句中从错误行开始的任何地方

我改变了3个部分。

  1. 我不能拥有2个gvTriggerProduct。

  2. 我现有代码中的一部分(不在此处)。缺少“.Value”。 Grek的提示Convert.ToByte(((DropDownList)rowItem.FindControl(“ddlMinTriggerQuantity”))。SelectedItem

  3. Error: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

     List<AddOnTrigger> triggerlist = new List<AddOnTrigger>();
    triggerList.Add(new AddOnTrigger
    {
     AddOnTriggerItems = gvTriggerProduct.Rows.Cast<GridViewRow>().Select(rowItem => new AddOnTriggerItem()
    {
        ProductTypeID = gvTriggerProduct.Rows[rowItem.RowIndex].Cells[1].Text.ToString(),
        ProductCode = gvTriggerProduct.Rows[rowItem.RowIndex].Cells[2].Text.ToString(),     
        CreatedTime = DateTime.Now,
        ModifiedTime = DateTime.Now
    }).ToList(),
    ActiveStatus = 1,
    CreatedTime = DateTime.Now,
    ModifiedTime = DateTime.Now}
    });
    
    ProjectA.TEST.BE.AddOn addOn = new ProjectA.TEST.BE.AddOn()
    { 
       AddCode = addCode,          
       CreatedTime = DateTime.Now,
       ModifiedTime = DateTime.Now,
       AddOnTriggers = triggerlist
       AddOnProducts = gvAddOnProduct.Rows.Cast<GridViewRow>().Select(rowAddOnProducts => new AddOnProduct()
       {
          ProductTypeID =    gvAddOnProduct.Rows[rowItem.RowIndex].Cells[2].Text.ToString(),    
          ProductCode = gvAddOnProduct.Rows[rowItem.RowIndex].Cells[2].Text.ToString(), 
          CreatedTime = DateTime.Now,
          ModifiedTime = DateTime.Now,
          AddOnProductAllotments = addOnProductAllotmentSession.Where(p => (p.ProductID == (Convert.ToString(((HiddenField)rowAddOnProducts.FindControl("ProductID")).Value )))).ToList(),      
    }).ToList()
    
    };