Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.Net-从包含数据绑定的标记调用方法_C#_Asp.net - Fatal编程技术网

C# ASP.Net-从包含数据绑定的标记调用方法

C# ASP.Net-从包含数据绑定的标记调用方法,c#,asp.net,C#,Asp.net,我在ASP.NET的C#中有一个用户控件。此用户控件在代码隐藏中有一个方法,定义如下: protected string GetGreeting(string name) { if (String.IsNullOrEmpty(name)) { return "Hello"; } else { return "Hello " + name; } } 我的标记如下所示: <asp:Repeater ID="listRepeater" ClientIDM

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

如何绑定数据源中记录的FullName属性?现在,我一直在看“Hello FullName”。我想看“你好,约翰·史密斯”之类的节目。我做错了什么


谢谢大家!

在.aspx中,您正在调用
GetGreeting(“全名”)
。这会逐字传递
“全名”

试一试


以下方面应起作用:

<%# GetGreeting(DataBinder.Eval(Container.DataItem, "FullName").ToString()) %> 

或简称:

<%# GetGreeting(Eval("FullName").ToString()) %> 

<%# GetGreeting(Eval("FullName").ToString()) %>