Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling a function in repeater asp.net

I want to call a function to bind data to Repeater . Do I need to Set dataSource Property of this control or Repeater .DataBind() will work.

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

I have written RepeaterDays.Databind(), but the function is not called.

This is displaying nothing.

like image 396
Mohan Sharma Avatar asked Aug 16 '26 07:08

Mohan Sharma


1 Answers

Is ChandanIdiot() a protected function that returns a string?

    protected string ChandanIdiot() {
        return "test";
    }

If you want to actually do some data processing, you will have to include a parameter:

    protected string ChandanIdiot(object obj) {
        return "test " + obj;
    }

And, assuming that there is a property called "Name" on the object that you are reapeating, you would have the following:

<asp:Label ID="lblDays" runat="server" Text='<%# ChandanIdiot(Eval("Name")) %>' />
like image 154
Daniel Dyson Avatar answered Aug 19 '26 16:08

Daniel Dyson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!