Professional Web Applications Themes

System.InvalidCastException: Specified cast is not valid. - ASP.NET General

Hello, Does somebody haves a solution for this? Thanks! Line 74: if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Line 75: Line 76: DataRowView drv = (DataRowView) e.Item.DataItem; Line 77: Source File: links.ascx.cs Line: 76 [InvalidCastException: Specified cast is not valid.] PortalICT.Links.myDataList_ItemDataBound(Object sender, DataListItemEventArgs e) in links.ascx.cs:76 System.Web.UI.WebControls.DataList.OnItemDataBound (DataListItemEventArgs e) +110 System.Web.UI.WebControls.DataList.CreateItem(Int3 2 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +139 System.Web.UI.WebControls.DataList.CreateControlHi erarchy(Boolean useDataSource) +686 System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e) +48 System.Web.UI.WebControls.BaseDataList.DataBind() +23 PortalICT.Links.Page_Load(Object sender, EventArgs e) in links.ascx.cs:39 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +29 System.Web.UI.Control.LoadRecursive() +92 System.Web.UI.Control.LoadRecursive() +92 System.Web.UI.Control.LoadRecursive() +92 System.Web.UI.Page.ProcessRequestMain() +713...

  1. #1

    Default System.InvalidCastException: Specified cast is not valid.

    Hello,

    Does somebody haves a solution for this?

    Thanks!



    Line 74: if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem) {
    Line 75:
    Line 76: DataRowView drv = (DataRowView) e.Item.DataItem;
    Line 77:


    Source File: links.ascx.cs Line: 76




    [InvalidCastException: Specified cast is not valid.]
    PortalICT.Links.myDataList_ItemDataBound(Object sender,
    DataListItemEventArgs e) in links.ascx.cs:76
    System.Web.UI.WebControls.DataList.OnItemDataBound (DataListItemEventArgs
    e) +110
    System.Web.UI.WebControls.DataList.CreateItem(Int3 2 itemIndex,
    ListItemType itemType, Boolean dataBind, Object dataItem) +139
    System.Web.UI.WebControls.DataList.CreateControlHi erarchy(Boolean
    useDataSource) +686
    System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e) +48
    System.Web.UI.WebControls.BaseDataList.DataBind() +23
    PortalICT.Links.Page_Load(Object sender, EventArgs e) in links.ascx.cs:39
    System.Web.UI.Control.OnLoad(EventArgs e) +67
    System.Web.UI.Control.LoadRecursive() +29
    System.Web.UI.Control.LoadRecursive() +92
    System.Web.UI.Control.LoadRecursive() +92
    System.Web.UI.Control.LoadRecursive() +92
    System.Web.UI.Page.ProcessRequestMain() +713



    Arjen Guest

  2. #2

    Default Re: System.InvalidCastException: Specified cast is not valid.

    "Arjen" <boah123hotmail.com> wrote
    > Does somebody haves a solution for this?
    > Line 74: if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem) {
    > Line 75:
    > Line 76: DataRowView drv = (DataRowView) e.Item.DataItem;
    > Line 77:
    > [InvalidCastException: Specified cast is not valid.]
    Arjen,
    If you use a DataSet to fill the DataList, then that is the correct syntax.
    However, if you use a SqlDataReader, then you must use cast the
    DataItem to a System.Data.Common.DbDataRecord.
    e.g.
    System.Data.Common.DbDataRecord dbDataRecord =
    (System.Data.Common.DbDataRecord) e.Item.DataItem;
    String s = dbDataRecord.GetString(0);

    --

    Thanks,
    Carl Prothman
    Microsoft ASP.NET MVP
    [url]http://www.able-consulting.com[/url]




    Carl Prothman [MVP] Guest

Similar Threads

  1. System.InvalidCastException was unhandled
    By Paul_Heinisch@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: October 3rd, 09:32 PM
  2. Replies: 0
    Last Post: January 28th, 02:55 PM
  3. dataGrid_ItemDataBound - System.InvalidCastException
    By AZNewsh in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: November 18th, 05:31 PM
  4. Replies: 1
    Last Post: April 16th, 06:27 AM
  5. Replies: 3
    Last Post: July 10th, 10:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139