O'Reilly Forums: Detailsviewpagersettings - Does Not Work - O'Reilly Forums

Jump to content

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

Detailsviewpagersettings - Does Not Work

#1 User is offline   snteran 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 28-April 12

Posted 28 April 2012 - 07:39 PM

I have created the example 8-4 that will display the DetailsView along with a Label.

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DetailsView.aspx.cs" Inherits="DetailsViewPagerSettings" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
   <title>DetailsView Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorkConnectionString %>" 
      
         SelectCommand="SELECT * FROM [SalesLT].[Customer]" />
      <asp:DetailsView ID="CustomerDetails" runat="server" DataSourceID="SqlDataSource1" AllowPaging="true"
         EmptyDataText="No data was found" DataKeyNames="CustomerID, RowGuid" EnablePagingCallbacks="True" PageIndex="5">
   <PagerSettings Mode="NumericFirstLast"
      PageButtonCount="20" Position="TopAndBottom" />
      </asp:DetailsView>
      <p>
         <asp:Label runat="server" ID="lblInfo" />
      </p>
   </div>
   </form>
</body>
</html>



Code Behind:

using System;
using System.Text;
using System.Web.UI;

public partial class DetailsViewPagerSettings : Page
{
    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();
       }
    }
}


Not sure why the Label does not appear.  I even added a Text in the label and that did not show up.

I'm very new to .Net, any help would be greatly appreciated.

Thanks,

0

#2 User is offline   snteran 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 28-April 12

Posted 29 April 2012 - 10:36 AM

View Postsnteran, on 28 April 2012 - 07:39 PM, said:

I have created the example 8-4 that will display the DetailsView along with a Label.

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DetailsView.aspx.cs" Inherits="DetailsViewPagerSettings" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
   <title>DetailsView Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorkConnectionString %>" 
      
         SelectCommand="SELECT * FROM [SalesLT].[Customer]" />
      <asp:DetailsView ID="CustomerDetails" runat="server" DataSourceID="SqlDataSource1" AllowPaging="true"
         EmptyDataText="No data was found" DataKeyNames="CustomerID, RowGuid" EnablePagingCallbacks="True" PageIndex="5">
   <PagerSettings Mode="NumericFirstLast"
      PageButtonCount="20" Position="TopAndBottom" />
      </asp:DetailsView>
      <p>
         <asp:Label runat="server" ID="lblInfo" />
      </p>
   </div>
   </form>
</body>
</html>



Code Behind:

using System;
using System.Text;
using System.Web.UI;

public partial class DetailsViewPagerSettings : Page
{
    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();
       }
    }
}


Not sure why the Label does not appear.  I even added a Text in the label and that did not show up.

I'm very new to .Net, any help would be greatly appreciated.

I did want to add that when I create a break point that I can see the info string populate correctly, however once it gets to the Text = "".

Thanks,


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