0
如何使用headertemplate訪問'HyperlinkID1'控件? 我想改變像下面的值,而是因爲它不斷告訴說:「名字‘HyperlinkID1’不在當前情況下存在」在Repeater HeaderTemplate中訪問超鏈接服務器控件
if (!IsPostBack)
{
HyperlinkID1.ImageUrl = "asc.jpg";//change image
}
else
{
HyperlinkID1.ImageUrl = "asc.jpg";//change image
}
<%@ Page Language="C#" %>
<!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 runat="server">
<title></title>
</head>
<script language="C#" runat="server">
public class PositionData
{
private string name;
private string ticker;
public PositionData(string name, string ticker)
{
this.name = name;
this.ticker = ticker;
}
public string Name
{
get
{
return name;
}
}
public string Ticker
{
get
{
return ticker;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HyperlinkID1.ImageUrl = "asc.jpg";//change image
}
else
{
HyperlinkID1.ImageUrl = "asc.jpg";//change image
}
if (!IsPostBack)
{
ArrayList values = new ArrayList();
values.Add(new PositionData("Microsoft", "Msft"));
values.Add(new PositionData("Intel", "Intc"));
values.Add(new PositionData("Dell", "Dell"));
Repeater1.DataSource = values;
Repeater1.DataBind();
}
}
</script>
<body>
<form runat="server">
<b>Repeater1:</b>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>Company</b>
<asp:HyperLink ID="HyperlinkID1" runat="server" ImageUrl="desc.jpg" NavigateUrl="nextpage.aspx">HyperLink</asp:HyperLink></td>
<td><b>Symbol</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "Name") %> </td>
<td><%# DataBinder.Eval(Container.DataItem, "Ticker") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>
你能給我一個關於如何使用它的例子嗎?這個例子http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.onitemcreated.aspx是可怕的。 –
已更新,以添加更多定義。 HTH –
謝謝,這是好的 –