如何访问数据列表中的asp控件。例如,我想,但目前不能,通过内联代码或代码隐藏文件访问HyperLink控件或ImageButton控件。访问数据列表中的asp控件
<asp:DataList ID="DataList1" runat="server" AlternatingItemStyle-CssClass="altArtStyle">
<HeaderTemplate>
<table>
<tr>
<td>
<asp:HyperLink ID="lnkTitle" runat="server" NavigateUrl="Default.aspx?order_by=title&direction=ASC" >
Title
</asp:HyperLink> <asp:ImageButton id="imgbtnTitle" src="/_images/hover-down.gif" runat="server"/>
</td>
</tr>
</table>
</HeaderTemplate>
你能给我一个简短的代码示例吗?我试图找到控制,但得到了投诉'对象引用未设置为对象的实例'。下面是我在绑定数据集后使用的代码。 昏暗imgbtnTitle作为的ImageButton =的FindControl( “imgbtnTitle”) 如果imgbtnTitle.ImageUrl = “/_images/hover-down.gif” 那么 imgbtnTitle.ImageUrl = “/_images/hover.gif” elseif的imgbtnTitle.ImageUrl =“ /_images/hover.gif“然后 imgbtnTitle.ImageUrl =”/_images/hover-down.gif“ End If – contactmatt 2009-09-21 16:23:42
看起来像Jason的覆盖。我只补充说你可能需要使用CType来施放控件。看看:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx – Steve 2009-09-21 21:01:03