Function call in asp.net repeater

I want to call a function to bind data to a Repeater. I need to set the 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 wrote RepeaterDays.Databind (), but the function is not called.

It does not display anything.

+3
source share
2 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 have to enable the option:

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

And, assuming that the object you are updating has the "Name" property, you should have the following:

<asp:Label ID="lblDays" runat="server" Text='<%# ChandanIdiot(Eval("Name")) %>' />
+9
source

Source:

<asp:TemplateField HeaderText="Unit Price">
    <ItemTemplate>
        <%# ChandanIdiot( Eval("product_unitprice"))%>
        <!--product_unitprice is table colomn name -->
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox>
    </EditItemTemplate>
</asp:TemplateField>

WITH#:

protected string ChandanIdiot(object ob) {
    string typ = ob.ToString(); //selected value stored in ob
    if (typ == "some function") {
        //do somthing 
    }

    return typ ; //value return to <%# ChandanIdiot( Eval("product_unitprice"))%>
}
+3
source

Source: https://habr.com/ru/post/1758706/


All Articles