English 中文(简体)
页: 1
原标题:asp.net calling a method from front end
  • 时间:2011-03-23 13:06:49
  •  标签:
  • c#
  • asp.net

i 在我后面的末尾有一种方法,即我要从我的前端呼吁,但似乎不能让它发挥作用。 我的守则是:

<% foreach(string item in Plants){ %>

    <li>
        <span class="folder">
            <asp:label ID="lblPlantName" runat="server" Text= <% GetPlantName(item) %> ></asp:label>
        </span>
    </li>

<%} %>

移植 姓名法应重新编号并填满案文。 但这不是出于某种原因。

是否有任何想法或建议?

最佳回答

请使用<代码><%=GetPlantName(项目) %>,而不是<% GetPlantName(项目) %>及方法应当公开或保护。

问题回答

送回你所需要的<代码>Response.Write,该编码用短文书写为<%=%>:

<%= GetPlantName(item) %>

虽然你的法典可能发挥作用(有其他人所建议的固定办法),但它并不好。 在你重新使用伙伴关系时,它是一种典型的伙伴关系方式。 NET——它像在公路上驾驶10辆MPH汽车。

一种良好做法是使用<代码>Repeater。 控制——它仍然很简单,而且更令人迷惑。

<代码>.aspx 我们现在将考虑这一点:

<asp:Repeater ID="rptPlants" runat="server">
    <HeaderTemplate><ol></HeaderTemplate>
    <FooterTemplate></ol></FooterTemplate>
    <ItemTemplate>
        <li>
            <span class="folder">
                <%# Container.DataItem %>
            </span>
        </li>
    </ItemTemplate>
</asp:Repeater>

为了对数据加以约束,在<代码>Page_Load中,在以下代码中具有这种代码的功能:

string[] arrPlants = new string[] { "Sacred Datura", "Kambroo", "Wallflower", "Beech  Retroflexa ", "Zephyr Flower" };
rptPlants.DataSource = arrPlants;
rptPlants.DataBind();

在您的情形下,仅将<代码>arrPlants与您的实际阵列相替换,Plants

有理由要求进一步细节或解释:





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签