O'Reilly Forums: Display Keys Of Currently Displayed Record In Detailsview Example - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Display Keys Of Currently Displayed Record In Detailsview Example

#1 User is offline   ambrewer 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 14-July 10

Posted 14 July 2010 - 12:58 AM

Hi,

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();
}
}


How do you display the keys for the currently displayed record in this example?

Thanks very much,
Andy
0

#2 User is offline   ambrewer 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 14-July 10

Posted 14 July 2010 - 01:19 AM

Sorry about bad formatting ...
Original question:

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)

How do you display the keys for the currently displayed record in this example?

Thanks very much,
Andy
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users