Get DetailsView’s page through primary key


I came across this question from this thread http://forums.asp.net/t/1237696.aspx. The asker found a solution at the end. The key part is to use DataRowView assciate with DetailsView. Here is the code in C#

protected void DetailsView1_OnDataBound(object sender, EventArgs e)

{

for (int i = 0; i < DetailsView1.PageCount; i++)

{

if (((DataRowView)DetailsView1.DataItem).DataView[i].Row["Id"].ToString() == "3") // when id=3, which page will be

//if (myDataRowView.DataView[i].Row[0].ToString() == "3")//working

{

DetailsView1.PageIndex = i;

break;

}

}

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s