0

我有一个 ListView 我在 asp.net 表单中添加了代码如下:

                    <asp:ListView runat="server" ID="ListView2" 
   GroupItemCount="1" onitemdatabound="ListView2_ItemDataBound">
               <LayoutTemplate>
                    <asp:PlaceHolder runat="server" ID="groupPlaceHolder"/>
                       </LayoutTemplate>
                        <GroupTemplate>
                          <asp:PlaceHolder runat="server" ID="itemPlaceHolder"/>
                        </GroupTemplate>
                        <ItemTemplate>
                          <div style="width: 200px; height: 220px; margin-left: 
                           230px; margin-top: -220px">
                                <a href='<%# GetAFTERburnDownloadHRef() %>'>
                                    <asp:Image ID="Image2" runat="server"   
                     ImageUrl="images/Download.jpg"/></a>
                          <img src="images/DownloadShadow.jpg"></div>
                        </ItemTemplate>
                        <GroupSeparatorTemplate>
                        </GroupSeparatorTemplate>
                        <EmptyDataTemplate>
                        </EmptyDataTemplate>
                    </asp:ListView>

有一个标签就是这个

<a href='<%# GetAFTERburnDownloadHRef() %>'>
                                <asp:Image ID="Image2" runat="server"   
                 ImageUrl="images/Download.jpg"/></a>

我必须用户类型免费用户和付费用户我想在运行时更改一些值

预付费用户价值将是这个

<a href='<%# GetAFTERburnDownloadHRef() %>'>
                                <asp:Image ID="Image2" runat="server"   
                 ImageUrl="images/Download.jpg"/></a>

并且当免费用户登录并访问该页面时,我希望它会在标签中添加一些 velue,它将显示类似这样的内容

<a href='<%# GetAFTERburnDownloadHRef() %>' name="popupmodal">
                                    <asp:Image ID="Image2" runat="server"   
                     ImageUrl="images/Download.jpg"/></a>

我想做的这个改变。我想知道如何name="popupmodal"通过 ListView2_ItemDataBound 中的代码添加

protected void ListView2_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        Image Image2 = (Image)e.Item.FindControl("Image2");
        //come code here for get <a></a> tag to made this change I want 
        string PlanType = "free";
        if (PlanType == Globals.PlaneType.PlanOne)        
        {
            //here i want to add name="popupmodal" in <a></a> like this  
            //<a name="popupmodal"></a>
            Image2.ImageUrl = "~/images/LockDownload.JPG";
        }
        else
        {
            Image2.ImageUrl = "~/images/Download.JPG";
        }
    }

任何朋友都知道我该如何添加这样做。

4

1 回答 1

0

您可以将锚设置为服务器端控件并在代码中更改其属性。标记可能如下所示:

<a id="popupmodal" runat="server" href='<%# GetAFTERburnDownloadHRef() %>' >
    <asp:Image ID="Image2" runat="server"   
        ImageUrl="images/Download.jpg"/>
</a>

在后面的代码中:

protected void ListView2_ItemDataBound(object sender, ListViewItemEventArgs e)
{

    Image Image2 = (Image)e.Item.FindControl("Image2");
    //come code here for get <a></a> tag to made this change I want 
    string PlanType = "free";
    if (PlanType == Globals.PlaneType.PlanOne)            
    {
        HtmlAnchor popupmodal = (HtmlAnchor)e.Item.FindControl("popupmodal");
        //here i want to add name="popupmodal" in <a></a> like this  
        //<a name="popupmodal"></a>
        popupmodal.Attributes.Add("name", "popupmodal");               
        Image2.ImageUrl = "~/images/LockDownload.JPG";
    }
    else
    {
        Image2.ImageUrl = "~/images/Download.JPG";
    }
}
于 2013-08-31T04:39:58.110 回答