您可以創建LinkButton
控件調用子程序/方法在你的ASPX代碼:
示例代碼:
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>LinkButton Example</title>
<script language="C#" runat="server">
void LinkButton_Click(Object sender, EventArgs e)
{
Label1.Text="You clicked the link button";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>LinkButton Example</h3>
<asp:LinkButton id="LinkButton1"
Text="Click Me"
Font-Names="Verdana"
Font-Size="14pt"
OnClick="LinkButton_Click"
runat="server"/>
<br />
<asp:Label id="Label1" runat="server" />
</form>
</body>
</html>
在您的特定情況下,您的主頁添加ContentPlaceHolder
:
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server" />
在您希望鏈接出現的頁面中添加一個Content
控件,如下所示:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
那麼你一定要foreach
鏈接,這樣做:
foreach (mammifere l in mamlist)
{
LinkButton linkButton = new LinkButton();
linkButton.Text = l.Nom;
linkButton.OnClick= "LinkButton_Click";
linkButton.ID = l.Nom;
Content1.Controls.Add(linkButton);
}
你有單引號雙引號,雙引號內... – IrishChieftain
如果你仔細觀察,你會發現它是3個獨立雙引號。雙引號是爲了使內容文本和單引號被用作實際的html標記 – AntoineLev