1
我在listview的InsertItemTemplate中有一個LinkButton。我想從背後的代碼設置誰的可見性。我正在使用此代碼,但在應用斷點時似乎控件未達到InsertItemTemplate。它只停留在ItemTemplate內。ListView中的訪問控件InsertItemTemplate
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserId"].ToString() == Request.QueryString["Id"].ToString())
{
foreach (ListViewItem item in lvAlbums.InsertItem.Items)
{
LinkButton linkButton = item.FindControl("LinkButton1") as LinkButton;
if (linkButton != null)
linkButton.Visible = false;
}
}
}
的源代碼:
<form id="form1" runat="server">
<asp:ListView ID="lvAlbums" runat="server"
DataSourceID="SqlDataSource1" GroupItemCount="3"
InsertItemPosition="LastItem">
<LayoutTemplate>
<table border="1">
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td3" width="150px" height="150px" align="center" style="background-color: #e8e8e8;color: #333333;">
<asp:HiddenField ID="hfPhotoID" runat="server" Value='<%# Eval("DefaultPhotID") %>' />
<a href='<%# "Photos.aspx?AlbumID="+Eval("AlbumID") %>'>
<asp:Image CssClass="Timg" runat="server" ID="imPhoto" ImageUrl='<%# "ThumbNail.ashx?ImURL="+Eval("Photo") %>' />
</a>
<br />
<b><asp:Label ID="lblAlbumName" runat="server" Text='<%# Eval("AlbumName") %>'></asp:Label> </b>
</td>
</ItemTemplate>
<InsertItemTemplate>
<td id="Td3" width="150px" height="150px" runat="server" align="center" style="background-color: #e8e8e8;color: #333333;">
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/CreateAlbum.aspx"> Create New Album1</asp:LinkButton>
<%-- <a href="CreateAlbum.aspx" id="createalbumlink" runat="server">
Create New Album
</a>--%>
</td>
</InsertItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SLIITComDBConnectionString %>"
SelectCommand="SELECT Album.AlbumID, Album.DefaultPhotID, Album.AlbumName, PhotAlbum.Photo FROM Album INNER JOIN PhotAlbum ON Album.DefaultPhotID = PhotAlbum.PhotoID where [email protected]">
<SelectParameters>
<asp:QueryStringParameter Name="userid" Type="int32" QueryStringField="id" />
<%--<asp:SessionParameter Name="userid" Type="String" SessionField="UserId" />--%>
</SelectParameters>
</asp:SqlDataSource>
</form>
我想你的代碼..加入 如果(會話[ 「用戶ID」]。的ToString()==的Request.QueryString [ 「身份證」]的ToString()){ 如果 (E .Item.ItemType == ListViewItemType.DataItem) 但它仍然沒有工作 – Arbaaz
您是否調試過代碼? – Adil
斷點不會適用於保護無效ContactsListView_ItemDataBound(對象發件人,ListViewItemEventArgs e) – Arbaaz