About GridView 's key fields

M

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
 
G

gnewsgroup

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;
}
}
 
M

marss

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top