Eval()
在 ASP.NET 中有何用途?
最佳答案
绑定(bind)数据绑定(bind)控件时,您可以使用 eval() 函数评估数据源中行的字段。
例如,您可以向 GridView 添加一列,如下所示:
<asp:BoundField DataField="YourFieldName" />
或者,这就是 eval 的方式:
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text='<%# Eval("YourFieldName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
看起来有点复杂,但它很灵活,因为您可以使用 eval() 函数设置控件的任何属性:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "ShowDetails.aspx?id="+Eval("Id") %>'
Text='<%# Eval("Text", "{0}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
关于asp.net - asp.net中Eval()有什么用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1793274/