About GridView 's key fields

Discussion in 'ASP .Net' started by marss, Jan 25, 2008.

  1. marss

    marss Guest

    Suppose I define a key field for GridView as is shown below.

    GridView1.DataKeyNames = new string[] { "EntityId" };
    GridView1.DataSource = ... //some data source
    GridView1.DataBind();

    Is there any way to find a gridview row by EntityId if data already
    has been bound for GridView1? I mean I have, for example, a button on
    a page and I want to find a gridview row by a known key field value
    within this button's click event handler.

    Thanks

    Mykola
    http://marss.co.ua
    marss, Jan 25, 2008
    #1
    1. Advertising

  2. marss

    marss Guest

    marss, Jan 25, 2008
    #2
    1. Advertising

  3. marss

    gnewsgroup Guest

    On Jan 25, 7:30 am, marss <> wrote:
    > On 25 Січ, 10:33, marss <> wrote:
    >
    > > Is there any way to find a gridview row by EntityId if data already
    > > has been bound for GridView1?

    >
    > I have got an answer.
    > If anybody is interested:http://forums.asp.net/t/1210657.aspx
    >
    > Mykolahttp://marss.co.ua


    Or maybe you can do this. Assign the Container.DataItemIndex to the
    CommandArgument property of your Button in the GridView, and then in
    your RowCommand event handler , you can say:

    protected void GridView1_RowCommand(object s, GridViewCommandEventArgs
    e)
    {
    if
    (((GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString()).Equals("EntityID")))
    {
    Label1.Text = "The row index is " + e.CommangArgument;
    }
    }
    gnewsgroup, Jan 26, 2008
    #3
  4. marss

    marss Guest

    On 26 Січ, 21:38, gnewsgroup <> wrote:

    > Or maybe you can do this. Assign the Container.DataItemIndex to the
    > CommandArgument property of your Button in the GridView, and then in
    > your RowCommand event handler , you can say:


    Thanks for answer.

    It is not exactly what I am looking for. When I said "button" I did
    not mean a button in the gridview but I mean a button on a page that
    is not attached to an appointed EntityId. The problem is how to find a
    gridview row by known (or calculated or extracted from a database)
    EntityId in any event handler that occurs after data has been bound.
    Using gridview key fields.

    Mykola
    http://marss.co.ua
    marss, Jan 28, 2008
    #4
    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?RWQgV2FycmVu?=

    GUID key fields and GridView/DetailView

    =?Utf-8?B?RWQgV2FycmVu?=, Apr 16, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    467
    =?Utf-8?B?RWQgV2FycmVu?=
    Apr 16, 2007
  2. call_me_anything
    Replies:
    4
    Views:
    444
    Pete Becker
    Sep 30, 2007
  3. Cyril.Liu
    Replies:
    0
    Views:
    428
    Cyril.Liu
    Dec 2, 2008
  4. middletree

    how to copy from fields to other fields

    middletree, Nov 5, 2003, in forum: ASP General
    Replies:
    1
    Views:
    146
    middletree
    Nov 5, 2003
  5. M P
    Replies:
    1
    Views:
    436
Loading...

Share This Page