Retrieve the data from the GridViewRow by column name instead of index

Discussion in '.NET' started by agora1983, Feb 11, 2008.

  1. agora1983

    agora1983

    Joined:
    Feb 11, 2008
    Messages:
    1
    Likes Received:
    0
    Hi there, everyone.
    I want to retrieve the data from the GridViewRow by column name instead of index.
    But the error prompt as "Cannot apply indexing with [] to an expression of type 'object ".
    How should I resolve it?
    Or I have to use something else instead of GridViewRow?


    protected void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e) {
    // If multiple ButtonField column fields are used, use the
    // CommandName property to determine which button was clicked.
    if( e.CommandName == "Select" ) {


    // Convert the row index stored in the CommandArgument
    // property to an Integer.
    int index = Convert.ToInt32( e.CommandArgument );

    // Get the project id from the appropriate
    // cell in the GridView control.
    GridViewRow selectedRow = GridView1.Rows[ index ];
    //The following line doesn't work
    Session[ "ProjectID" ] = selectedRow.DataItem[ "ProjectID" ];

    // These two lines work
    Session[ "ClientName" ] = selectedRow.Cells[ 2 ].Text;
    Session[ "ProjectName" ] = selectedRow.Cells[ 3 ].Text;


    }
    }

    Thanks in advance.

    -- Joe
     
    agora1983, Feb 11, 2008
    #1
    1. Advertisements

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. carlos perez
    Replies:
    0
    Views:
    565
    carlos perez
    Jun 8, 2004
  2. needin4mation@gmail.com

    Is there a way to get a column by name instead of ordinal?

    needin4mation@gmail.com, Aug 2, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,308
    needin4mation@gmail.com
    Aug 2, 2005
  3. msnews

    use column name instead of index

    msnews, Sep 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    486
    Eliyahu Goldin
    Sep 28, 2005
  4. Rich Morey
    Replies:
    0
    Views:
    421
    Rich Morey
    Jun 5, 2004
  5. John Walker

    Retrieve Datagrid Element Index by Name

    John Walker, Nov 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    263
    Phillip Williams
    Nov 11, 2005
  6. Rich Morey

    Deleting cells by name instead of index?

    Rich Morey, Jun 5, 2004, in forum: Javascript
    Replies:
    6
    Views:
    331
    Rich Morey
    Jun 8, 2004
  7. Tomasz Chmielewski

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

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    607
    Tomasz Chmielewski
    Mar 4, 2008
  8. ashok.dhananjeyan@gmail.com
    Replies:
    6
    Views:
    392
Loading...