在转发器asp.net中调用函数

Moh*_*rma 3 asp.net repeater

我想调用一个函数将数据绑定到Repeater.我是否需要设置此控件或Repeater .DataBind()的dataSource属性.

<asp:Repeater ID="RepeaterDays" runat="server">
    <ItemTemplate>
        <ul>
            <asp:Label ID="lblDays" runat="server" Text='<%#ChandanIdiot()%>'></asp:Label>
        </ul>
    </ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

我写过RepeaterDays.Databind(),但是没有调用该函数.

这没什么.

Dan*_*son 9

ChandanIdiot()是一个返回字符串的受保护函数吗?

    protected string ChandanIdiot() {
        return "test";
    }
Run Code Online (Sandbox Code Playgroud)

如果您想要实际进行一些数据处理,则必须包含一个参数:

    protected string ChandanIdiot(object obj) {
        return "test " + obj;
    }
Run Code Online (Sandbox Code Playgroud)

并且,假设您正在重新定位的对象上有一个名为"Name"的属性,您将拥有以下内容:

<asp:Label ID="lblDays" runat="server" Text='<%# ChandanIdiot(Eval("Name")) %>' />
Run Code Online (Sandbox Code Playgroud)