如何调用从aspx页code隐藏的方法? [英] How to call a code-behind method from aspx page?
本文介绍了如何调用从aspx页code隐藏的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经包含了一个名为场中的目标的 DevList 是这样定义的
I've an object that contains a field called DevList which is defined like this
public List<string> DevList { get; set; }
我还定义了一个名为方法的 DisplayListOfDevelopers 是应该来连接的开发商名单,并显示为一个字符串。
I also defined a method called DisplayListOfDevelopers that is supposed to concatenate the list of developers and display it as a one string.
这是我如何打电话是从ASPX方法。
This is how I'm calling the method from aspx.
<asp:TemplateField HeaderText = "Developer(s)">
<ItemTemplate>
<asp:Label
ID="_lblDevList"
runat="server"
Text= '<%# DisplayListOfDevelopers(DevList) %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
不过,我得到这个错误:DevList'这个名字并不在目前的情况下存在
我缺少的东西吗?
_gvStatus = ds;
_gvStatus.DataBind();
在哪里DS只是一个对象列表包含在 DevList 现在。
感谢您的帮助。
推荐答案
假设这是你的类的样子:
Assuming this is how your class looks:
public class MyItem
{
public List<string> DevList { get; set; }
}
这
ds = List<MyItem>();
做到这一点:
在您的code-背后:
In your code-behind:
protected string DisplayListOfDevelopers(object _devList)
{
//Cast your dev list into the correct object
}
在你的标记:
<asp:TemplateField HeaderText = "Developer(s)">
<ItemTemplate>
<asp:Label
ID="_lblDevList"
runat="server"
Text= '<%# DisplayListOfDevelopers(Eval("DevList")) %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
只是一定要使函数在code-后面保护或公开。
Just be sure to make the function in your code-behind is protected or public.
这篇关于如何调用从aspx页code隐藏的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文