Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在嵌套中继器中使用Datalist项_C#_Html_Asp.net_Datarepeater_Asprepeater - Fatal编程技术网

C# 在嵌套中继器中使用Datalist项

C# 在嵌套中继器中使用Datalist项,c#,html,asp.net,datarepeater,asprepeater,C#,Html,Asp.net,Datarepeater,Asprepeater,我有一个博客的代码,它在数据列表中嵌套了一个repeater控件 我试图将repeater控件图像的alt标记指定为通过datalist发送的帖子的标题,但是,由于它有不同的数据源,因此它不允许我执行此操作 有没有关于我如何做到这一点的建议 这是我的密码: <asp:DataList runat="server" ID="DataList1" ItemStyle-CssClass="row1BackgroundBlock" OnItemDataBound="DataList1_ItemDa

我有一个博客的代码,它在数据列表中嵌套了一个repeater控件

我试图将repeater控件图像的alt标记指定为通过datalist发送的帖子的标题,但是,由于它有不同的数据源,因此它不允许我执行此操作

有没有关于我如何做到这一点的建议

这是我的密码:

<asp:DataList runat="server" ID="DataList1" ItemStyle-CssClass="row1BackgroundBlock" OnItemDataBound="DataList1_ItemDataBound" >
    <ItemTemplate>
<!-- <%#Eval("PostId")%> post -->
<div class="dateBox"><asp:Label ID="Label1" runat="server" ForeColor="#ffffff" Font-Bold="False" Text='<%# Eval("PublicationDate","{0:dd/MM/yyyy}") %>' CssClass="postmetadata"></asp:Label></div>
<div class="roundPanelStack">
<h2><asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Engine2010.Blog.BlogLinksManager.GetFullPostsLinks((int)Eval("PostId"), (object)Eval("FURL")) %>'><%# Eval("Title") %></asp:HyperLink></h2>
<ul><li class="postBy">Posted in <a href="<%#CommonFunctions.GetTreeURL(146).ToString() + "?categoryid=" + Eval("CategoryID") %>"><%#Eval("CategoryName")%></a> by <%#Eval("Author")%></li><li class="last">{<%# Engine2010.Blog.PostComment.GetAllByPostId(int.Parse(Eval("PostId").ToString()), 766).Rows.Count.ToString()%> comments}</li></ul>

<div class="thumbWindow">
<div style="border:7px solid #fff;display:block;height:95px;left:1px;position:absolute;top:1px;width:95px;z-index:5;"></div>
        <asp:Repeater ID="repImgs" runat="server">
            <ItemTemplate>
                <img class="thumb_view" src="/uploads/images/Blog/<%# Eval("Directory").ToString().Substring(Eval("Directory").ToString().LastIndexOf("\\")+1) %>/<%# Eval("Name") %>" alt="" border="0" width="143" height="143" />
            </ItemTemplate>
        </asp:Repeater>

        <asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible="false">
        <img src="/includes/images/general/default.jpg" alt="Default" border="0" width="110" height="110" />
        </asp:PlaceHolder>
</div>

<p>
<asp:Label ID="Label2" runat="server" Text='<%#CommonFunctions.Remove_HTML_Tags(Eval("Description").ToString()) %>' CssClass="entry"></asp:Label>
</p>

<div class="linksMore">
<asp:HyperLink ID="FullStoryLink" runat="server" NavigateUrl='<%# Engine2010.Blog.BlogLinksManager.GetFullPostsLinks((int)Eval("PostId"), (object)Eval("FURL")) %>' CssClass="fullstory">Read Full Post</asp:HyperLink><a class="spacer">&nbsp;//&nbsp;</a><asp:HyperLink ID="CommentsLink" runat="server" NavigateUrl='<%# Engine2010.Blog.BlogLinksManager.GetFullPostsLinks((int)Eval("PostId"), (object)Eval("FURL")) + "#comment" %>' CssClass="comments">Comment</asp:HyperLink>

</div>


</div>
<!-- /first post -->
    </ItemTemplate>
</asp:DataList>
by
  • {comments}
  • /“alt=”“border=“0”width=“143”height=“143”/

    阅读全文//评论
    后端:

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater repImages = (Repeater)e.Item.FindControl("repImgs");                          // Child repeater with images for room
            string amenText = ((DataRowView)e.Item.DataItem).Row.ItemArray[7].ToString();
              DirectoryInfo folderBr = new DirectoryInfo(Server.MapPath("~/uploads/images/Blog/") + amenText);
            // List<Engine2010.ImageObj> imageObjs = folderBr.GetImagesInPath();
    
            if (folderBr.Exists)
              {
                  repImages.DataSource = folderBr.GetFiles("thumb*.*");                                                        // Bind room images to child repeater  
                    repImages.DataBind();
    
                  if (repImages.Items.Count == 0)
                  {
                      PlaceHolder placeholder1 = (PlaceHolder)e.Item.FindControl("PlaceHolder1");
                      placeholder1.Visible = true;
                  }
              }
              else {
                  PlaceHolder placeholder1 = (PlaceHolder)e.Item.FindControl("PlaceHolder1");
                  placeholder1.Visible = true;
              }
        }
    }
    
    protectedvoid DataList1\u ItemDataBound(对象发送方,DataListItemEventArgs e)
    {
    如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem)
    {
    repImages=(Repeater)e.Item.FindControl(“repImgs”);//带有房间图像的子中继器
    字符串amenText=((DataRowView)e.Item.DataItem).Row.ItemArray[7].ToString();
    DirectoryInfo folderBr=新的DirectoryInfo(Server.MapPath(“~/uploads/images/Blog/”)+amenText);
    //List imageObjs=folderBr.GetImagesInPath();
    if(folderBr.存在)
    {
    repImages.DataSource=folderBr.GetFiles(“thumb**”);//将房间图像绑定到子转发器
    repImages.DataBind();
    if(repImages.Items.Count==0)
    {
    占位符占位符1=(占位符)e.Item.FindControl(“占位符1”);
    占位符1.可见=真;
    }
    }
    否则{
    占位符占位符1=(占位符)e.Item.FindControl(“占位符1”);
    占位符1.可见=真;
    }
    }
    }
    
    在数据列表的ItemDataBound事件中,绑定
    repImages
    repatter控件后,使用
    RepeaterItem
    迭代每个项目,然后找到您的img控件并在alt标记中指定标题,如下所示-

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater repImages = (Repeater)e.Item.FindControl("repImgs"); 
            string amenText = ((DataRowView)e.Item.DataItem).Row.ItemArray[7].ToString();
            DirectoryInfo folderBr = new DirectoryInfo(Server.MapPath("~/uploads/images/Blog/") + amenText);
    
            if (folderBr.Exists)
            {
                repImages.DataSource = folderBr.GetFiles("thumb*.*");      // Bind room images to child repeater  
                repImages.DataBind();
    
                if (repImages.Items.Count == 0)
                {
                    PlaceHolder placeholder1 = (PlaceHolder)e.Item.FindControl("PlaceHolder1");
                    placeholder1.Visible = true;
                }
    
                // Iterate thru each item of your child repeate control.
                foreach (RepeaterItem repeaterItem in repImages.Items)
                {
                    if (repeaterItem.ItemType == ListItemType.Item ||
                        repeaterItem.ItemType == ListItemType.AlternatingItem)
                    {
                        ((HtmlImage)(repeaterItem.FindControl("imgId"))).Alt = amenText; // Assume amenText is the title of your post
                    }
    
                }
            }
            else
            {
                PlaceHolder placeholder1 = (PlaceHolder)e.Item.FindControl("PlaceHolder1");
                placeholder1.Visible = true;
            }
        }
    }
    

    祝你好运……

    这个答案非常有效。非常感谢:)