后面的代码似乎不适用于ASP:LABEL变量 [英] Code behind does not seem to work with ASP:LABEL variable
问题描述
我有一个看起来很简单的问题,但是我无法弄清楚为什么它不起作用.我已经在其他应用程序中做到了这一点.
我有一个ASPX页面,该页面的顶部仅显示数据,仅供参考,而Gridview则显示可编辑的相关记录.我使用ASP:LABELs在页面顶部显示数据字段.后台代码处理在页面加载期间检索数据.我得到的是没有数据的现场图例.我已经尝试了我所知道的一切,并且已经尝试了一切我可以使用的Google.下面的代码显示我已经删除了所有数据字段,并将其减少为一个变量(m),该变量在后面的代码"中设置为"StuffToShow".结果页面应显示
案例编号:StuffToShow",但仅显示案例编号:"
我不知道为什么要这么做.您可以在已注释掉的区域中看到我没有运气尝试过其他东西.随附的代码不完整,仅包含我认为与其简短相关的内容.
任何想法或建议将不胜感激.我有一个看不到的简单原因,就是我无法看到.
谢谢!!!
I have a problem that seems so simple to fix but I cannot figure out why this is not working. I have done this in other apps with no problem.
I have an ASPX page that displays data at the top for info only and a Gridview to show related records that can be edited. I use ASP:LABELs to display the data fields at the top of the page. The Code Behind handles retrieving the data during Page Load. What I am getting is the field legend with no data. I have tried everything I know and have tried everything I can Google. The code below shows that I have removed all the data fields and reduced it to a variable (m) that gets set in the Code Behind to "StuffToShow". The resulting page should show
"Case Number: StuffToShow" but only shows "Case Number: "
I cannot figure out why it is doing this. You can see in the areas commented out that I tried other things with no luck. The attached code is not complete and includes only what I thought is relevant to keep it short.
Any ideas or suggestions will be much appreciated. There has got to be a simple reason for this not working that I just cannot see.
Thank you!!!
<%@ Page Language="C#" MasterPageFile="~/SiteMaster.master" AutoEventWireup="false" CodeFile="DisplayDerivativesDetail.aspx.cs" Inherits="DisplayDerivativesDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PageHeading" Runat="Server">
<h3>Monthly Derivatives - Display Detail</h3>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageContent" Runat="Server">
<div id="main">
<asp:Label ID="lblInstructions" runat="server" Text="Display Detail Information:" >
</asp:Label><br /><br />
<!-- drop down list for detail status -->
<asp:Label ID="lblStatus" runat="server" Text="Detail Status:" Width="80px" ></asp:Label>
<asp:DropDownList ID="ddlStatus" runat="server" Width="75px">
<asp:ListItem Text="Active" Selected="True" Value="AC" />
<asp:ListItem Text="Inactive" Value="IN" />
</asp:DropDownList><br /><br />
<asp:Label ID="Label1" runat="server" Text="Case Number:" ></asp:Label>
<asp:Label ID="m" runat="server" ></asp:Label><br /><br />
<!-- <asp:Label ID="Label2" runat="server" Text="NCP Name: "></asp:Label>
<asp:Label ID="lblNCPName" runat="server" Text="Data" Width="280px"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Court Number: " Width="125px"></asp:Label>
<asp:Label ID="lblCourtNumber" runat="server" Width="125px"></asp:Label>
<asp:Label ID="Label4" runat="server" Text="Monthly Amount: " ></asp:Label>
<asp:Label ID="lblMonthlyAmt" runat="server" Width="125px"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server" Text="Start Date: " ></asp:Label>
<asp:Label ID="lblStartDate" runat="server" Width="125px"></asp:Label>
<asp:Label ID="Label6" runat="server" Text="Review Date: "></asp:Label>
<asp:Label ID="lblReviewDate" runat="server" Width="125px"></asp:Label>
<asp:Label ID="Label7" runat="server" Text="End Date: "></asp:Label>
<asp:Label ID="lblEndDate" runat="server" Width="125px"></asp:Label>
<br /><br /> -->
<!-- grid of Detail records for a selected Case -->
<asp:GridView ID="gvDetail" Runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateEditButton="True"
AutoGenerateColumns="False"
BackColor="LightGray"
BorderColor="#3366CC"
BorderStyle="None"
BorderWidth="1px"
CellPadding="4"
DataKeyNames="CaseID"
DataSourceID="odsDetail"
Font-Size="X-Small"
OnRowEditing="gvDetail_RowEditing"
PagerSettings-Mode="Numeric"
ShowFooter="True" >
<FooterStyle CssClass="HeaderFooter"></FooterStyle>
<HeaderStyle Font-Bold="True" Wrap="True" CssClass="HeaderFooter"></HeaderStyle>
<AlternatingRowStyle Font-Bold="False" BackColor="GhostWhite"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="PaymentDate" HeaderText="Payment Date" SortExpression="PaymentDate" ItemStyle-Wrap="false" />
<asp:BoundField DataField="Amount" HeaderText="Payment Amt" SortExpression="Amount" ItemStyle-Wrap="false" />
<asp:BoundField DataField="DetailComment" HeaderText="Comment" SortExpression="DetailComment" ItemStyle-Wrap="false" />
<asp:BoundField DataField="DetailAddedBy" HeaderText="Added By" SortExpression="DetailAddedBy" ItemStyle-Wrap="false" />
<asp:BoundField DataField="DetailAdded" HeaderText="Added" SortExpression="DetailAdded" ItemStyle-Wrap="false" />
<asp:BoundField DataField="DetailUpdatedBy" HeaderText="Updated By" SortExpression="DetailUpdatedBy" ItemStyle-Wrap="false" />
<asp:BoundField DataField="DetailUpdated" HeaderText="Updated" SortExpression="DetailUpdatedBy" ItemStyle-Wrap="false" />
<asp:TemplateField HeaderText="Detail ID" SortExpression="DetailID" visible="false">
<EditItemTemplate>
<asp:TextBox ID="eitDetailID" runat="server" ReadOnly="True" Text='<%# Bind("DetailID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="itDetailID" runat="server" Text='<%# Bind("DetailID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Case ID" SortExpression="CaseID" visible="false">
<EditItemTemplate>
<asp:TextBox ID="eitCaseID" runat="server" ReadOnly="True" Text='<%# Bind("CaseID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="itCaseID" runat="server" Text='<%# Bind("CaseID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="CaseID" HeaderText="Case ID" SortExpression="CaseID" Visible="false" />
</Columns>
</asp:GridView>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ParameterPasser;
public partial class DisplayDerivativesDetail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//* Grab the CaseID passed from DisplayDerivativesCases.aspx and convert to integer *//
//int intCaseID;
//string strCaseID = Request.QueryString["CaseID"];
//intCaseID = Convert.ToInt32(strCaseID);
//// Get Case Info for display only
//DerivativesBAL.DerivativesBAL obj10 = new DerivativesBAL.DerivativesBAL();
//DataSet dsName = obj10.GetCase(intCaseID);
m.Text = "StuffToShow";
//lblCaseNumber.Text = dsName.Tables[0].Rows[0]["CaseNumber"].ToString();
//lblNCPName.Text = dsName.Tables[0].Rows[0]["NCPNameLast"] + ", " +
//dsName.Tables[0].Rows[0]["NCPNameFirst"] + " " +
//dsName.Tables[0].Rows[0]["NCPNameMiddle"].ToString();
//lblCourtNumber.Text = dsName.Tables[0].Rows[0]["CourtNumber"].ToString();
//lblMonthlyAmt.Text = dsName.Tables[0].Rows[0]["MonthlyAmt"].ToString();
//lblStartDate.Text = dsName.Tables[0].Rows[0]["StartDate"].ToString();
//lblReviewDate.Text = dsName.Tables[0].Rows[0]["ReviewDate"].ToString();
//lblEndDate.Text = dsName.Tables[0].Rows[0]["EndDate"].ToString();
//if (lblCaseNumber.Text == null)
//{
// lblCaseNumber.Text = "EMPTY";
//}
//else
//{
// lblCaseNumber.Text = "HAS INFO";
//}
}
推荐答案
There must be something wrong, but as I''ve given this code a real execution on my IDE (Visual Studio 2010), it works absolutely fine. It shows-"Case Number: StuffToShow". I also checked manipulating the commented part of the code and all those works fine as expected.
I suggest you to check if there is any other manipulation before the page loads or if any variable is there in masterfile with same id.
谢谢
Sunny K
Hi,
There must be something wrong, but as I''ve given this code a real execution on my IDE (Visual Studio 2010), it works absolutely fine. It shows-"Case Number: StuffToShow". I also checked manipulating the commented part of the code and all those works fine as expected.
I suggest you to check if there is any other manipulation before the page loads or if any variable is there in masterfile with same id.
Thanks
Sunny K
Another Idea might be, if it is not finding the code file. verify the spelling and that it can find it.
I don''t understand why it works, but it just worked for me using VB.Net
I used a stock VS2008 build for a webapplication.
Dropped Into the the deault aspx:
Another Idea might be, if it is not finding the code file. verify the spelling and that it can find it.
I don''t understand why it works, but it just worked for me using VB.Net
I used a stock VS2008 build for a webapplication.
Dropped Into the the deault aspx:
<asp:Label ID="Label1" runat="server" Text="Case Number:" ></asp:Label>
<asp:Label ID="m" runat="server" ></asp:Label><br /><br />
and dropped in below to the default aspx vb file:
and dropped in below to the default aspx vb file:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
m.Text = "StuffToShow"
End Sub
and the result was
and the result was
Case Number:StuffToShow
First off, I want to thank all who responded. I was glad to hear that my code was working. After reading the responses I reevaluated what I had done. I always work with the code and have never used the designer. So, I pulled up the designer in VS 2005. I could see the "m" variable in the design view and opened it''s properties. I looked in Events and found that DataBinding and Load were blank. I selected Page_Load for both and it worked.
Not sure yet why but this gives me a whole new place to look and learn.
Thanx again. This forum always comes through and provides helpful hints for exploring.
First off, I want to thank all who responded. I was glad to hear that my code was working. After reading the responses I reevaluated what I had done. I always work with the code and have never used the designer. So, I pulled up the designer in VS 2005. I could see the "m" variable in the design view and opened it''s properties. I looked in Events and found that DataBinding and Load were blank. I selected Page_Load for both and it worked.
Not sure yet why but this gives me a whole new place to look and learn.
Thanx again. This forum always comes through and provides helpful hints for exploring.
这篇关于后面的代码似乎不适用于ASP:LABEL变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!