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
    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. 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. msnews

    use column name instead of index

    msnews, Sep 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    401
    Eliyahu Goldin
    Sep 28, 2005
  2. silverfox_1188
    Replies:
    0
    Views:
    3,520
    silverfox_1188
    Jul 25, 2006
  3. walterb
    Replies:
    0
    Views:
    1,467
    walterb
    Sep 13, 2007
  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:
    360
    Tomasz Chmielewski
    Mar 4, 2008
  5. ashok.dhananjeyan@gmail.com
    Replies:
    6
    Views:
    211
Loading...

Share This Page