gpt4 book ai didi

c# - ASP.Net - 从包含数据绑定(bind)的标记调用方法

转载 作者:可可西里 更新时间:2023-11-01 08:38:54 26 4
gpt4 key购买 nike

我在 ASP.NET 中有一个用 C# 编写的用户控件。此用户控件在代码隐藏中有一个方法,定义如下:

protected string GetGreeting(string name)
{
if (String.IsNullOrEmpty(name))
{
return "Hello";
}
else
{
return "Hello " + name;
}
}

我的标记如下所示:

<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>

如何绑定(bind)数据源中记录的 FullName 属性?现在,我不断看到“Hello FullName”。我想看到类似“Hello John Smith”的内容。我做错了什么?

谢谢!

最佳答案

在您的 .aspx 中,您正在调用 GetGreeting("FullName")。这从字面上传递了 "FullName"

尝试

GetGreeting(Eval("FullName").ToString())

关于c# - ASP.Net - 从包含数据绑定(bind)的标记调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7132578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com