DataKeys(Index): Scope issue

Discussion in 'ASP .Net Datagrid Control' started by Lee C., Feb 27, 2004.

  1. Lee C.

    Lee C. Guest

    I can access the dg's DataKeys values (table primary key values) from
    events raised by objects outside of the dg. For example, from a
    Button1_Click, where the button is not in the dg, but elsewhere on the
    page. I cannot access the dg's DataKeys values from events raised by
    objects inside of the dg (Edit button, Delete button, etc.), which is
    where I really need to. I get, "Index was out of range. Must be
    non-negative and less than the size of the collection. Parameter name:
    index". I am hard coding the index, for now, and that doesn't help.

    If I check the DataGrid1.DataKeys.Count, logically, from events raised
    within the dg, Count = 0, and from outside the dg, Count = 6.

    I just don't get this. Can someone please explain?

    Thanks,
    Lee
    Lee C., Feb 27, 2004
    #1
    1. Advertising

  2. I solved it. The problem was not specific to the DataKeys. The problem was
    that the code in all of my ItemCommand events fires everytime any one of
    them fires. I guess I am mixing two samples, found on the Web, that don't
    mix so well, but I got it sorted out.

    The datagrid has built-in methods for handling record edits, updates,
    cancels, and deletes, but not inserts. So, I had to use the generic
    OnItemCommand which fires all aforementioned methods. That's the part I
    wasn't getting before, but now I see what's happening.

    , Lee


    "Lee C." <> wrote in message
    news:...
    > I can access the dg's DataKeys values (table primary key values) from
    > events raised by objects outside of the dg. For example, from a
    > Button1_Click, where the button is not in the dg, but elsewhere on the
    > page. I cannot access the dg's DataKeys values from events raised by
    > objects inside of the dg (Edit button, Delete button, etc.), which is
    > where I really need to. I get, "Index was out of range. Must be
    > non-negative and less than the size of the collection. Parameter name:
    > index". I am hard coding the index, for now, and that doesn't help.
    >
    > If I check the DataGrid1.DataKeys.Count, logically, from events raised
    > within the dg, Count = 0, and from outside the dg, Count = 6.
    >
    > I just don't get this. Can someone please explain?
    >
    > Thanks,
    > Lee
    Lee Cichanowicz, Feb 27, 2004
    #2
    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. Marina

    DataList.DataKeys problem

    Marina, Jul 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,804
    the Dude
    Jul 17, 2003
  2. VB Programmer

    Gridview multiple datakeys issue

    VB Programmer, Oct 15, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    393
    VB Programmer
    Oct 15, 2007
  3. Joel Finkel

    DataGrid1.DataKeys[e.Item.ItemIndex] array index out of bounds

    Joel Finkel, Sep 4, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    300
    Joel Finkel
    Sep 4, 2003
  4. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    266
    Tomasz Chmielewski
    Mar 4, 2008
  5. Replies:
    0
    Views:
    154
Loading...

Share This Page