Asp.net 如何嵌套<;%%&燃气轮机;从代码隐藏文件访问变量时?
我有这个,很好用Asp.net 如何嵌套<;%%&燃气轮机;从代码隐藏文件访问变量时?,asp.net,Asp.net,我有这个,很好用 <asp:LinkButton ID="abc" runat="server" Text='<%#Eval("artist") %>' PostBackUrl='<%#"~/welcome.aspx?artist="+Eval("artist")%>'> 现在我想替换test中的artist,它是一个变量.cs文件 有人能告诉你怎么做吗?给你举个例子: ASCX: 政务司司长: public分部类\u默认值:System.Web.U
<asp:LinkButton ID="abc" runat="server"
Text='<%#Eval("artist") %>'
PostBackUrl='<%#"~/welcome.aspx?artist="+Eval("artist")%>'>
现在我想替换test中的artist,它是一个变量.cs文件
有人能告诉你怎么做吗?给你举个例子:
ASCX:
政务司司长:
public分部类\u默认值:System.Web.UI.Page
{
公共字符串FieldName=@“Name”;
受保护的无效页面加载(对象发送方、事件参数e)
{
列表艺术家=新列表();
添加(新的ArtistInfo(){Name=“Lady GaGa”,Location=“Nebraska”});
添加(新的ArtistInfo(){Name=“Justin Timberlake”,Location=“Memphis”});
repItems.DataSource=艺术家;
repItems.DataBind();
}
}
公共类ArtistInfo
{
公共字符串名称{get;set;}
公共字符串位置{get;set;}
}
因为
只意味着在数据绑定期间计算此表达式并返回其结果,所以您可以在其中放入任何需要的内容。在本例中,我们使用FieldName参数调用Eval,该参数是在代码隐藏中定义的字符串。举个例子:
ASCX:
政务司司长:
public分部类\u默认值:System.Web.UI.Page
{
公共字符串FieldName=@“Name”;
受保护的无效页面加载(对象发送方、事件参数e)
{
列表艺术家=新列表();
添加(新的ArtistInfo(){Name=“Lady GaGa”,Location=“Nebraska”});
添加(新的ArtistInfo(){Name=“Justin Timberlake”,Location=“Memphis”});
repItems.DataSource=艺术家;
repItems.DataBind();
}
}
公共类ArtistInfo
{
公共字符串名称{get;set;}
公共字符串位置{get;set;}
}
因为
只意味着在数据绑定期间计算此表达式并返回其结果,所以您可以在其中放入任何需要的内容。在本例中,我们使用FieldName参数调用Eval,FieldName是在代码隐藏中定义的字符串
<asp:Repeater ID="repItems" runat="server">
<ItemTemplate>
<asp:Panel ID="pnlItem" runat="server">
<asp:LinkButton ID="lnkItem" runat="server" Text='<%# Eval(FieldName) %>' ></asp:LinkButton>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
public partial class _Default : System.Web.UI.Page
{
public string FieldName = @"Name";
protected void Page_Load(object sender, EventArgs e)
{
List<ArtistInfo> artists = new List<ArtistInfo>();
artists.Add( new ArtistInfo() { Name = "Lady GaGa", Location = "Nebraska" });
artists.Add( new ArtistInfo() { Name = "Justin Timberlake", Location = "Memphis" });
repItems.DataSource = artists;
repItems.DataBind();
}
}
public class ArtistInfo
{
public string Name { get; set; }
public string Location { get; set; }
}