views:

194

answers:

1

Hi all,

In classic ASP if you wanted to send a user to a specific page you would send/create a URL like : posts.asp?id=24 ...the querystring indicating the post.

Well, in asp.net using a DetailsView control bound to a dataset, how do I do the same thing? In the address bar, all i see is posts.aspx when I'm paging through the records, no querystring part. How do I send a user to posts.aspx?id=24 when its a detailsview control on the page.

Note: I'm interested in sending a user to a specific postid not a specific index in the dataset.

Regards Melt

A: 

A quick way to do this would be to bind your details view in page load as:

string id = Request.QueryString["id"];
if(!string.IsNullOrEmpty(id))
{
   myDataSet.Filter = String.Format("id = {0}", id);
}

myDetailsView.DataSource = myDataSet;
myDetailsView.DataBind();

MSDN has more information on filtering and sorting DataSets.

Edit: In order to change to a specific page, maybe do something like this in page load:

int selectedPage = -1;
string id = Request.QueryString["id"];
if(!string.IsNullOrEmpty(id))
{
  for(int i = 0; i< myDataSet.Tables[0].Rows.Count; i++)
  {
     DataRow row = myDataSet.Tables[0].Rows[i];
     if(row["id"].ToString().Equals(id))
     {
         selectedPage = i;
         continue;
     }
  }
}

myDetailsView.DataSource = myDataSet;
myDetailsView.PageIndex = selectedPage;
myDetailsView.DataBind();
Jim Schubert
Hi, thanks, that does answer my question as I phrased it, unfortunately filtering means the user can't continue to page the records using Next/Previous. Do you know of any way to do this and leave my dataset intact?Thanks for the reply
Melt
I updated the answer with a way to find the pageIndex. I don't usually deal with DataSets, so there may be a quicker/easier way to do this if you check out the docs: http://msdn.microsoft.com/en-us/library/system.data.dataset_methods.aspx Thanks.
Jim Schubert