简单的数据绑定问题
我有一个页面,其中有一个 myCustomWebProfile 类型的公共属性。
在后面的代码中,我有一个文本框,我正在尝试将文本框绑定到上述网络配置文件的属性。
无论我使用哪种绑定语法变体,文本框在渲染时都不会被填充。
任何帮助将不胜感激。
这是 C# 代码隐藏类:
public partial class Profile : selfSvcPage
{
public WebProfile pgProfile { get; set; }
protected void Page_Init(object sender, EventArgs e)
{
pgProfile = WebProfile.Current;
}
protected void Page_Load(object sender, EventArgs e)
{
object o = WebProfile.Current.FirstName;
//Successfully populates with a string
object b = DataBinder.Eval(pgProfile, "FirstName");
//Successfully populates with a string
}
}
这是代码标记:
<telerik:RadTextBox ID="FirstName" Text='<%# Eval("pgProfile.FirstName") %>' SkinID="formText" CssClass="formField" runat="server"/>
I have a page, which has a public property of type myCustomWebProfile.
In code behind I have a textbox, and I am trying to bind the text box, to a property of my web profile described above.
No matter which variations of the binding syntax I use - the textbox is never populated when it's rendered.
Any help will be greatly appreciated.
Here is the C# code-behind class:
public partial class Profile : selfSvcPage
{
public WebProfile pgProfile { get; set; }
protected void Page_Init(object sender, EventArgs e)
{
pgProfile = WebProfile.Current;
}
protected void Page_Load(object sender, EventArgs e)
{
object o = WebProfile.Current.FirstName;
//Successfully populates with a string
object b = DataBinder.Eval(pgProfile, "FirstName");
//Successfully populates with a string
}
}
Here is the code markup:
<telerik:RadTextBox ID="FirstName" Text='<%# Eval("pgProfile.FirstName") %>' SkinID="formText" CssClass="formField" runat="server"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
还有这个:
根据您的情况,您可能希望在早期阶段进行绑定。有关详细信息,请参阅此:
为什么会<%= %>表达式作为服务器控件上的属性值会导致编译错误?
重要部分:'作为我注意到的最后一件事......当我尝试使用 <%# %> 时+ Control.DataBind(),然后我得到了我所期望的。 '
Try this:
And this:
In your situation you might want to bind at an earlier stage. Refer to this for details:
Why will <%= %> expressions as property values on a server-controls lead to a compile errors?
The important part: 'As the last thing i noticed... When i try with <%# %> + Control.DataBind(), then i get what i would expect. '
您可以在 Page_Load 中执行此操作吗:
确保 pgProfile 的初始化发生在上面的代码之前。
Can you just do this in your Page_Load:
Make sure the initialization of your pgProfile happens before the code above.
我从你的代码中得到的是你在该类中有一个
类 Profile
,你已经为类 webProfile 建立了一个属性。
现在通过使用这个属性,你正在尝试分配值,我想你可以尝试这样的事情
What i got from your code is you have a
class Profile
in that class you have made a property of a class webProfile.
Now by using this property you are trying to assign value i think you can try some thing like this