ASP.Net - 从标记,其中包括数据绑定调用方法 [英] ASP.Net - Call Method from markup that includes data-binding
本文介绍了ASP.Net - 从标记,其中包括数据绑定调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中的ASP.NET用户控件。此用户控件中定义的code-背后的方法如下:
I have a user control in C# in ASP.NET. This user control has a method in the code-behind that is defined as follows:
protected string GetGreeting(string name)
{
if (String.IsNullOrEmpty(name))
{
return "Hello";
}
else
{
return "Hello " + name;
}
}
我的标记如下所示:
My markup looks like the following:
<asp:Repeater ID="listRepeater" ClientIDMode="Static" runat="server" OnLoad="listRepeater_Load">
<HeaderTemplate>
<table id="listTable" style="width:100%;">
<thead><tr>
<th>Greeting</th>
<th>Actions</th>
</tr></thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# GetGreeting("FullName")%></td>
<td><a href='#'>view info</a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
我如何记录的全名属性绑定在我的数据来源?现在,我一直看到你好全名。我想看到类似你好约翰·史密斯。我在做什么错了?
How do I bind the FullName property of the record in my data source? Right now, I keep seeing "Hello FullName". I want to see something like "Hello John Smith". What am I doing wrong?
感谢您!
推荐答案
在你的.aspx,你正在调用 GetGreeting(全名)
。这通过全名
字面上。
In your .aspx, you are calling GetGreeting("FullName")
. This passes "FullName"
literally.
尝试
GetGreeting(Eval("FullName").ToString())
这篇关于ASP.Net - 从标记,其中包括数据绑定调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文