单值aspx页面绑定 [英] Single value binding in aspx page
本文介绍了单值aspx页面绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要几十个来自DB查询属性来填充一个aspx页面。我知道怎么做是对财产控件的文本属性分配在背后这样的code:
I need to populate an aspx page with dozens of properties from a db query. What I know how to do is to assign the property to the Text attribute of the control in the code behind like this:
protected void Page_Load(object sender, EventArgs e)
{
string param = Request.QueryString["param"];
// p will have dozens of properties
M.P p = new M.P(param);
aLabel.Text = p.aProperty;
anotherLabel.Text = p.anotherProperty;
和在ASPX code:
And in the aspx code:
<asp:Label ID="aLabel" runat="server"></asp:Label>
<asp:Label ID="anotherLabel" runat="server"></asp:Label>
我想什么做的是只是直接在aspx页面绑定属性,而无需在后面像这样code需要分配:
What I would like to do is to just bind the properties directly in the aspx page without the need to the assignment in the code behind like this:
protected void Page_Load(object sender, EventArgs e)
{
string param = Request.QueryString["param"];
M.P p = new M.P(param);
this.DataBind();
Value of the aProperty: <%# p.aProperty %>
Value of the anotherProperty: <%# p.anotherProperty #>
但我失去了一些东西重要,因为编译器给我的错误名称'P'不会在目前情况下存在
。如何使它工作?
推荐答案
您可能有这样的事情( P
移动财产)
You could have something like this (p
moved as property)
C#
protected M.P p {get; set;}
protected void Page_Load(object sender, EventArgs e)
{
string param = Request.QueryString["param"];
p = new M.P(param);
}
ASPX
<asp:Label ID="aLabel" runat="server"><%= p.aProperty %></asp:Label>
<asp:Label ID="anotherLabel" runat="server"><%= p.anotherProperty %></asp:Label>
这篇关于单值aspx页面绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文