About GridView "s key fields

About GridView "s key fields

am 25.01.2008 09:33:12 von marss

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

Re: About GridView "s key fields

am 25.01.2008 13:30:58 von marss

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

Mykola
http://marss.co.ua

Re: About GridView "s key fields

am 26.01.2008 20:38:44 von gnewsgroup

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)].Va lue.ToString()).=
Equals("EntityID")))
{
Label1.Text =3D "The row index is " + e.CommangArgument;
}
}

Re: About GridView "s key fields

am 28.01.2008 07:24:27 von marss

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