Jump to content


Photo

Display Keys Of Currently Displayed Record In Detailsview Example


  • Please log in to reply
1 reply to this topic

#1 ambrewer

ambrewer

    New Member

  • Members
  • Pip
  • 2 posts

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

#2 ambrewer

ambrewer

    New Member

  • Members
  • Pip
  • 2 posts

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users