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

Discussion in 'ASP .Net Datagrid Control' started by Joel Finkel, Sep 4, 2003.

  1. Joel Finkel

    Joel Finkel Guest

    Folks,

    Can someone please explan why this this line of code works fine when executed within an ItemCommand (that is, once the data are fully bound), but throws an exception when it is executed withn an ItemBound (when the data are being bound to the grid)? The exception is an array out of bounds.

    string strID = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

    Thanks in advance.

    Joel Finkel
     
    Joel Finkel, Sep 4, 2003
    #1
    1. Advertising

  2. Joel Finkel

    Joel Finkel Guest

    Many thanks!

    "Prasad" <> wrote in message news:...
    Hi

    You need to check the ItemType before using the Statement. Try this :

    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    string strID = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
    }



    HTH
    Prasad
    "Joel Finkel" <> wrote in message news:...
    Folks,

    Can someone please explan why this this line of code works fine when executed within an ItemCommand (that is, once the data are fully bound), but throws an exception when it is executed withn an ItemBound (when the data are being bound to the grid)? The exception is an array out of bounds.

    string strID = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

    Thanks in advance.

    Joel Finkel
     
    Joel Finkel, Sep 4, 2003
    #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. =?Utf-8?B?ZHdlbndhQGNvbXBhbnlhYmMuY29t?=

    Re: Index Out of Bounds Error

    =?Utf-8?B?ZHdlbndhQGNvbXBhbnlhYmMuY29t?=, Oct 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    498
    =?Utf-8?B?ZHdlbndhQGNvbXBhbnlhYmMuY29t?=
    Oct 20, 2004
  2. Mark Olbert
    Replies:
    1
    Views:
    463
    Luke Zhang [MSFT]
    Jan 25, 2006
  3. Biff
    Replies:
    4
    Views:
    1,925
    E. Robert Tisdale
    Jan 31, 2005
  4. Method Man

    Index out of bounds question

    Method Man, Oct 14, 2004, in forum: C Programming
    Replies:
    26
    Views:
    644
    Dan Pop
    Oct 22, 2004
  5. Scott M.

    e.Item.ItemIndex and e.Item.DataSetIndex

    Scott M., Nov 1, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    7
    Views:
    264
    Steven Cheng[MSFT]
    Apr 13, 2005
Loading...

Share This Page