CType(e.Item.Cells(3).Controls(1), textbox) fails when key is set to READONLY

Discussion in 'ASP .Net Datagrid Control' started by Keith-Earl, Jul 14, 2004.

  1. Keith-Earl

    Keith-Earl Guest

    The code could not be simpler:
    Dim txtProjectID As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)

    Dim dblProjectID As Double = CDbl(txtProjectID.Text)


    Run-time exception thrown : System.ArgumentOutOfRangeException - Specified
    argument was out of the range of valid values.
    Parameter name: index

    e.Item.Cell(1) is valid. When I take away the READONLY attribute everything
    works fine. What is really bizzare is that ALL Cells throw the same error
    when I set the READONLY attribute to TRUE. When I remove it I can reference
    all Cells in the Quickwatch window and in code. ProjectID is one of two
    keys. The end-user should never change my keys in this app.

    To make it even more interesting, I have another simple app (simple
    code/description table) that does not exhibit this behavior.

    What gives?

    Keith
     
    Keith-Earl, Jul 14, 2004
    #1
    1. Advertising

  2. Keith-Earl

    MA Guest

    "Keith-Earl" <css@NO_SPAMConsultWithUs.com> wrote in message
    news:...
    > The code could not be simpler:
    > Dim txtProjectID As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
    >
    > Dim dblProjectID As Double = CDbl(txtProjectID.Text)
    >
    >
    > Run-time exception thrown : System.ArgumentOutOfRangeException - Specified
    > argument was out of the range of valid values.
    > Parameter name: index
    >
    > e.Item.Cell(1) is valid. When I take away the READONLY attribute

    everything
    > works fine. What is really bizzare is that ALL Cells throw the same error
    > when I set the READONLY attribute to TRUE. When I remove it I can

    reference
    > all Cells in the Quickwatch window and in code. ProjectID is one of two
    > keys. The end-user should never change my keys in this app.
    >
    > To make it even more interesting, I have another simple app (simple
    > code/description table) that does not exhibit this behavior.
    >
    > What gives?
    >
    > Keith
    >
    >


    When e.Item.Cells(1).Controls(0) is read only, there is no TextBox in it.
    Get the value via a string instead. I don´t use VB usually, but it could
    look like this in C# (without testing ;) :
    string strProjectID = e.Item.Cells(1).Text;

    /Marre
     
    MA, Jul 14, 2004
    #2
    1. Advertising

  3. Keith-Earl

    Keith-Earl Guest

    Will try that and report back.

    Please explain why I have a SIMPLE code/description table where the PK is
    READONLY and it works.
     
    Keith-Earl, Jul 14, 2004
    #3
  4. Keith-Earl

    Keith-Earl Guest

    Please read MA's post and my follow up. Thanks for helping.
     
    Keith-Earl, Jul 14, 2004
    #4
  5. It's just a guess. Could be that if you set ReadOnly, the control renders as
    internal cell text and not as a control? Then Controls(0) would throw an
    exception.

    Eliyahu

    "Keith-Earl" <css@NO_SPAMConsultWithUs.com> wrote in message
    news:...
    > The code could not be simpler:
    > Dim txtProjectID As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
    >
    > Dim dblProjectID As Double = CDbl(txtProjectID.Text)
    >
    >
    > Run-time exception thrown : System.ArgumentOutOfRangeException - Specified
    > argument was out of the range of valid values.
    > Parameter name: index
    >
    > e.Item.Cell(1) is valid. When I take away the READONLY attribute

    everything
    > works fine. What is really bizzare is that ALL Cells throw the same error
    > when I set the READONLY attribute to TRUE. When I remove it I can

    reference
    > all Cells in the Quickwatch window and in code. ProjectID is one of two
    > keys. The end-user should never change my keys in this app.
    >
    > To make it even more interesting, I have another simple app (simple
    > code/description table) that does not exhibit this behavior.
    >
    > What gives?
    >
    > Keith
    >
    >
     
    Eliyahu Goldin, Jul 14, 2004
    #5
  6. Keith-Earl

    MA Guest

    "Keith-Earl" <css@NO_SPAMConsultWithUs.com> wrote in message
    news:...
    > Will try that and report back.
    >
    > Please explain why I have a SIMPLE code/description table where the PK is
    > READONLY and it works.
    >
    >


    Sorry, but I don´t know if I understand what you mean.

    /Marre
     
    MA, Jul 15, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S_K
    Replies:
    1
    Views:
    3,648
    Yankee Imperialist Dog
    Jun 5, 2008
  2. Doogie
    Replies:
    5
    Views:
    1,879
    E-ric
    Oct 10, 2012
  3. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    313
    Joel Finkel
    Sep 1, 2003
  4. Ravichandran Mahalingam

    (TextBox) (e.Item.Cells[2].Controls[0]) - Cast Invalid - Cannot update.

    Ravichandran Mahalingam, Jan 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    189
    Ravichandran Mahalingam
    Jan 12, 2004
  5. Jonathan Hyatt
    Replies:
    1
    Views:
    1,945
    Jonathan Hyatt
    Jun 8, 2004
Loading...

Share This Page