错误:在尝试填充Radgrid时,对象必须实现IConvertible

时间:2012-03-02 11:36:10

标签: c# asp.net telerik radgrid objectdatasource

我正在尝试填充网格时遇到问题 它的数据源基本上是Object Data Source,如下所示:

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="ObjectDataSource1">
  <MasterTableView AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
    <RowIndicatorColumn>
      <HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>

    <ExpandCollapseColumn>
      <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
    <Columns>
        <telerik:GridBoundColumn DataField="TitleChoiceIncident"
            HeaderText="TitleChoiceIncident" ReadOnly="True"
            SortExpression="TitleChoiceIncident" UniqueName="TitleChoiceIncident">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ValueChoiceIncident"
            HeaderText="ValueChoiceIncident" ReadOnly="True"
            SortExpression="ValueChoiceIncident" UniqueName="ValueChoiceIncident">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idAgir" DataType="System.Int32"
            HeaderText="idAgir" SortExpression="idAgir" UniqueName="idAgir">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idUtilisateur" DataType="System.Int32"
            HeaderText="idUtilisateur" SortExpression="idUtilisateur"
            UniqueName="idUtilisateur">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idEmetteur" DataType="System.Int32"
            HeaderText="idEmetteur" SortExpression="idEmetteur" UniqueName="idEmetteur">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idTypeAction" DataType="System.Int32"
            HeaderText="idTypeAction" SortExpression="idTypeAction"
            UniqueName="idTypeAction">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idEntreprise" DataType="System.Int32"
            HeaderText="idEntreprise" SortExpression="idEntreprise"
            UniqueName="idEntreprise">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idFamille" DataType="System.Int32"
            HeaderText="idFamille" SortExpression="idFamille" UniqueName="idFamille">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idProjet" DataType="System.Int32"
            HeaderText="idProjet" SortExpression="idProjet" UniqueName="idProjet">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idGroupeContact" DataType="System.Int32"
            HeaderText="idGroupeContact" SortExpression="idGroupeContact"
            UniqueName="idGroupeContact">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idOrdinateur" DataType="System.Int32"
            HeaderText="idOrdinateur" SortExpression="idOrdinateur"
            UniqueName="idOrdinateur">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idParent" DataType="System.Int32"
            HeaderText="idParent" SortExpression="idParent" UniqueName="idParent">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idEtatIncident" DataType="System.Int32"
            HeaderText="idEtatIncident" SortExpression="idEtatIncident"
            UniqueName="idEtatIncident">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idSousCategorie" DataType="System.Int32"
            HeaderText="idSousCategorie" SortExpression="idSousCategorie"
            UniqueName="idSousCategorie">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="date" HeaderText="date"
            SortExpression="date" UniqueName="date">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="heure" HeaderText="heure"
            SortExpression="heure" UniqueName="heure">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="durée" HeaderText="durée"
            SortExpression="durée" UniqueName="durée">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="priorite" DataType="System.Int32"
            HeaderText="priorite" SortExpression="priorite" UniqueName="priorite">
        </telerik:GridBoundColumn>
        <telerik:GridCheckBoxColumn DataField="blocage" DataType="System.Boolean"
            HeaderText="blocage" SortExpression="blocage" UniqueName="blocage">
        </telerik:GridCheckBoxColumn>
        <telerik:GridCheckBoxColumn DataField="fait" DataType="System.Boolean"
            HeaderText="fait" SortExpression="fait" UniqueName="fait">
        </telerik:GridCheckBoxColumn>
        <telerik:GridCheckBoxColumn DataField="facturable" DataType="System.Boolean"
            HeaderText="facturable" SortExpression="facturable" UniqueName="facturable">
        </telerik:GridCheckBoxColumn>
        <telerik:GridCheckBoxColumn DataField="alerterAgir" DataType="System.Boolean"
            HeaderText="alerterAgir" SortExpression="alerterAgir" UniqueName="alerterAgir">
        </telerik:GridCheckBoxColumn>
        <telerik:GridBoundColumn DataField="dateRappel" DataType="System.DateTime"
            HeaderText="dateRappel" SortExpression="dateRappel" UniqueName="dateRappel">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="descriptionAgir"
            HeaderText="descriptionAgir" SortExpression="descriptionAgir"
            UniqueName="descriptionAgir">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="cheminFichier" HeaderText="cheminFichier"
            SortExpression="cheminFichier" UniqueName="cheminFichier">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="objet" HeaderText="objet"
            SortExpression="objet" UniqueName="objet">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="lieu" HeaderText="lieu"
            SortExpression="lieu" UniqueName="lieu">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="dateSaisit" DataType="System.DateTime"
            HeaderText="dateSaisit" SortExpression="dateSaisit" UniqueName="dateSaisit">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="dateAgir" DataType="System.DateTime"
            HeaderText="dateAgir" SortExpression="dateAgir" UniqueName="dateAgir">
        </telerik:GridBoundColumn>
        <telerik:GridCheckBoxColumn DataField="isAgenda" DataType="System.Boolean"
            HeaderText="isAgenda" SortExpression="isAgenda" UniqueName="isAgenda">
        </telerik:GridCheckBoxColumn>
        <telerik:GridCheckBoxColumn DataField="isAgendaPerso" DataType="System.Boolean"
            HeaderText="isAgendaPerso" SortExpression="isAgendaPerso"
            UniqueName="isAgendaPerso">
        </telerik:GridCheckBoxColumn>
        <telerik:GridCheckBoxColumn DataField="isIncidentGen" DataType="System.Boolean"
            HeaderText="isIncidentGen" SortExpression="isIncidentGen"
            UniqueName="isIncidentGen">
        </telerik:GridCheckBoxColumn>
        <telerik:GridBoundColumn DataField="dateDebut" DataType="System.DateTime"
            HeaderText="dateDebut" SortExpression="dateDebut" UniqueName="dateDebut">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="dateEtatIncident"
            DataType="System.DateTime" HeaderText="dateEtatIncident"
            SortExpression="dateEtatIncident" UniqueName="dateEtatIncident">
        </telerik:GridBoundColumn>
        <telerik:GridCheckBoxColumn DataField="isPause" DataType="System.Boolean"
            HeaderText="isPause" SortExpression="isPause" UniqueName="isPause">
        </telerik:GridCheckBoxColumn>
        <telerik:GridBoundColumn DataField="idTypeDemande" DataType="System.Int32"
            HeaderText="idTypeDemande" SortExpression="idTypeDemande"
            UniqueName="idTypeDemande">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="TempsEstime" HeaderText="TempsEstime"
            SortExpression="TempsEstime" UniqueName="TempsEstime">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Acceptation" HeaderText="Acceptation"
            SortExpression="Acceptation" UniqueName="Acceptation">
        </telerik:GridBoundColumn>
        <telerik:GridCheckBoxColumn DataField="Accord" DataType="System.Boolean"
            HeaderText="Accord" SortExpression="Accord" UniqueName="Accord">
        </telerik:GridCheckBoxColumn>
        <telerik:GridBoundColumn DataField="DerniereDateModif"
            DataType="System.DateTime" HeaderText="DerniereDateModif"
            SortExpression="DerniereDateModif" UniqueName="DerniereDateModif">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="idExchange" HeaderText="idExchange"
            SortExpression="idExchange" UniqueName="idExchange">
        </telerik:GridBoundColumn>
        <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="ImageColumnValider">
            <ItemTemplate>
                <asp:ImageButton ID="ImageButtonValidation" runat="server" ImageUrl="~/img/validation.gif"
                        CommandName="Submit" CommandArgument='<%#Eval("idAgir")%>' ToolTip="Valider le ticket"
                        OnClick="Submit_Click" OnClientClick="return confirm('Êtes vous sûr de vouloir valider ce ticket?');" />
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="ImageColumnDecliner">
            <ItemTemplate>
                <asp:ImageButton ID="ImageButtonDecliner" runat="server" ImageUrl="~/img/croix.png"
                        CommandName="Decline" CommandArgument='<%#Eval("idAgir")%>' ToolTip="Décliner la proposition"
                        OnClick="Decline_Click" OnClientClick="return confirm('Êtes vous sûr de vouloir décliner la proposition?');" />
            </ItemTemplate>
        </telerik:GridTemplateColumn>
    </Columns>
  </MasterTableView>

  <HeaderContextMenu EnableAutoScroll="True"></HeaderContextMenu>
</telerik:RadGrid>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetNewAgirsByClient" TypeName="DBAccess.DAOAgir">
    <SelectParameters>
        <asp:SessionParameter Name="idContact" SessionField="contact" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>

我收到此错误,我不明白为什么? 有谁知道这可能来自哪里?

编辑:这是我选择数据的地方:

public static List<Agir> GetNewAgirsByClient(int idContact)
{
    DataClassesActilogDataContext db = ContextSingleton.GetDataContext();

    List<Agir> ListeAgir;

    var v = from i in db.Agir
            where (i.Agir_Contact.Any(a => a.idContact == idContact)
            || i.Projet.Projet_Contact.Any(a => a.idContact == idContact))
            && (i.idEtatIncident == 1 || i.idEtatIncident == 11) && i.Accord == null
            select i;

    ListeAgir = v.ToList();

    return ListeAgir;
}

这是跟踪:

[InvalidCastException: L'objet doit implémenter IConvertible.]
   System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +4049209
   System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +126
   System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges) +63
   System.Web.UI.WebControls.Parameter.get_ParameterValue() +40
   System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +261
   System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +270
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   Telerik.Web.UI.GridTableView.PerformSelect() +28
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   Telerik.Web.UI.GridTableView.DataBind() +364
   Telerik.Web.UI.RadGrid.DataBind() +173
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

2 个答案:

答案 0 :(得分:0)

您必须尝试使用​​System.Convert类转换任何自定义对象,否则RadGrid会尝试这样做。如果要将任何自定义对象传递给网格,请使用IConvertible实现该类型。

答案 1 :(得分:0)

  • Source

      

    您的问题可能是由于为特定数据字段设置了错误的DataType。 .NET Framework正在尝试强制转换类型并搜索IConvertable接口并抛出异常。为了解决您的问题,您应该确定哪个列有问题并更正DataType。请注意,根据提供的代码,很难确定哪个列导致问题,因为不知道来自ObjectDataSource的类型。

  •