The example code for the DetailsView control (Example 8-4, DetailsView.aspx.cs) is supposed to display the datakeynames and values for the currently selected record. These values are obtained on page_load.
The key values are different to the currently displayed record. That is, if you run the example and click the 'next' record, the detailsview displays the second record but the label displays the keys for the previous. Is this because the currently selected record is set after page_load?
CODE
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
StringBuilder info = new StringBuilder();
info.AppendFormat("You are viewing record {0} of {1}<br />",
CustomerDetails.DataItemIndex.ToString(), CustomerDetails.DataItemCount.ToString());
for (int i = 0; i < CustomerDetails.DataKeyNames.Length; i++)
{
info.AppendFormat("{0} : {1}<br />", CustomerDetails.DataKeyNames[i], CustomerDetails.DataKey.Values[i]);
}
info.AppendFormat("Selected Value : {0}", CustomerDetails.SelectedValue.ToString());
lblInfo.Text = info.ToString();
}
}
{
if (IsPostBack)
{
StringBuilder info = new StringBuilder();
info.AppendFormat("You are viewing record {0} of {1}<br />",
CustomerDetails.DataItemIndex.ToString(), CustomerDetails.DataItemCount.ToString());
for (int i = 0; i < CustomerDetails.DataKeyNames.Length; i++)
{
info.AppendFormat("{0} : {1}<br />", CustomerDetails.DataKeyNames[i], CustomerDetails.DataKey.Values[i]);
}
info.AppendFormat("Selected Value : {0}", CustomerDetails.SelectedValue.ToString());
lblInfo.Text = info.ToString();
}
}
How do you display the keys for the currently displayed record in this example?
Thanks very much,
Andy












