Professional Web Applications Themes

Specified Cast is not Valid - ASP.NET Data Grid Control

Can someone help with this issue? Here is my error (my code follows) Error Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid Source Error: Line 200: Dim OC, PQ, PA As Intege Line 201: Dim tb As TextBo Line 202: tb = CType(e.Item.Cells(0).Controls(0), TextBox Line 203: OC = tb.Tex Line 204: tb = CType(e.Item.Cells(1).Controls(0), TextBox Code Private Sub dgDiscIP_UpdateCommand(ByVal source As Object, ByVal e ...

  1. #1

    Default Specified Cast is not Valid

    Can someone help with this issue? Here is my error (my code follows)

    Error
    Specified cast is not valid.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Specified cast is not valid

    Source Error:

    Line 200: Dim OC, PQ, PA As Intege
    Line 201: Dim tb As TextBo
    Line 202: tb = CType(e.Item.Cells(0).Controls(0), TextBox
    Line 203: OC = tb.Tex
    Line 204: tb = CType(e.Item.Cells(1).Controls(0), TextBox

    Code

    Private Sub dgDiscIP_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgDiscIP.UpdateComman
    'Identify what datagrid row was update
    Dim key As String = dgDiscIP.DataKeys(e.Item.ItemIndex).ToString(

    'get changed values out of the datagrid ro
    Dim OC, PQ, PA As Intege
    Dim tb As TextBo
    tb = CType(e.Item.Cells(0).Controls(0), TextBox
    OC = tb.Tex
    tb = CType(e.Item.Cells(1).Controls(0), TextBox
    PQ = tb.Tex
    tb = CType(e.Item.Cells(2).Controls(0), TextBox
    PA = tb.Tex

    'Find corresponding row in the data tabl
    Dim r As dsIP.tbl04aSIP_DiscRo
    r = DsIP1.tbl04aSIP_Disc.FindBySEQ(key

    'Update the Row by changing values in the row you located abov
    r.Override = O
    r.Qty_Alt = P
    r.Amt_Alt = P

    'Send changes from the dataset to the database by calling the DA's Update Metho
    SqlDataAdapter1.Update(DsIP1

    dgDiscIP.DataBind(

    'Switch the current row in the grid out of edit mod
    dgDiscIP.EditItemIndex = -

    dgDiscIP.DataBind(

    End Sub
    DJONES Guest

  2. #2

    Default Specified Cast Is Not Valid

    Server
    VS.NET 2003
    SQLServer 2000
    IIS 66.0
    ----------------------------------
    1. I have sever web pages with datagrids that draw info from different
    respecitve SQLServer tables.

    2. The datagrids have Item Templates columns for editing data.

    3. The pages initially load their data into the datagrids fine, but when I
    edit data, I get the 'Specified Cast IS Not Valid' error below.

    4. NOTE: All these pages worked fine for Many Months for data editing, and
    then this error started at the same time on all the pages with datagrids.

    Other pages with just text boxes used for editing still work fine..

    5. Was there anything in any automatic Windows or Net Framework update that
    might have changed something?

    Thanks very much for any help.

    I can't figure this one out. I hadn't changed anything.

    Alan




    Server Error in '/' Application.
    ----------------------------------------------------------------------------
    ----

    Code Section
    ----------------------------------------
    protected void RowChanged(object sender, System.EventArgs e)
    {
    // Add changed record ID's to ChangedRecordList for SaveRecord loop
    DataGridItem dgi = (DataGridItem) (((Control) sender).NamingContainer);
    int recordID = int.P(dgi.Cells[0].Text);

    // Add to list if not already there
    if(!ChangedRecordIDList.Contains(recordID))
    {
    ChangedRecordIDList.Add(recordID);
    }
    }

    Error Message:
    --------------------------------
    Specified cast is not valid.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Specified cast is not valid.

    Source Error:

    Line 167: {
    Line 168: // Add changed record ID's to ChangedRecordList for SaveRecord
    loop
    Line 169: DataGridItem dgi = (DataGridItem) (((Control)
    sender).NamingContainer);
    Line 170: int recordID = int.P(dgi.Cells[0].Text);
    Line 171:


    Source File: d:\inetpub\wwwroot\winfundssql\default.aspx.cs Line: 169

    Stack Trace:

    [InvalidCastException: Specified cast is not valid.]
    NetFunds.Values.RowChanged(Object sender, EventArgs e) in
    d:\inetpub\wwwroot\winfundssql\default.aspx.cs:169
    System.Web.UI.WebControls.TextBox.OnTextChanged(Ev entArgs e) +108

    System.Web.UI.WebControls.TextBox.System.Web.UI.IP ostBackDataHandler.RaisePo
    stDataChangedEvent() +26
    System.Web.UI.Page.RaiseChangedEvents() +115
    System.Web.UI.Page.ProcessRequestMain() +1081





    Alan Z. Scharf Guest

Similar Threads

  1. Replies: 1
    Last Post: April 16th, 06:27 AM
  2. Replies: 1
    Last Post: August 6th, 03:26 AM
  3. Please help on Specified cast is not valid exception
    By Jeffrey Sanchez in forum ASP.NET Web Services
    Replies: 0
    Last Post: August 4th, 04:12 PM
  4. Cast from type 'DBNull' to type 'String' is not valid error
    By Rob in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 28th, 09:11 PM
  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