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>    
    </He开发者_JAVA百科aderTemplate>
    <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?
Thank you!
In your .aspx, you are calling GetGreeting("FullName"). This passes "FullName" literally. 
Try
GetGreeting(Eval("FullName").ToString())
The following should work:
<%# GetGreeting(DataBinder.Eval(Container.DataItem, "FullName").ToString()) %> 
or a shorter form:
<%# GetGreeting(Eval("FullName").ToString()) %> 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论