本文介绍了如何删除dynamicaly创建< D​​IV>如果标记IMG SRC =在asp.net C#“未定义”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择的文件夹content.This文件夹包含图像,当我选择该文件夹,将选择所有content.plus它正在IMG SRC undefind。
所以我需要删除的我如何删除如果src的使用asp.net C#未定义

 < D​​IV ID =细胞级=BOX2>
    &所述; A HREF =未定义>
        &所述; IMG宽度=260px高度=135​​pxSRC =未定义
            ALT =
            风格=的box-shadow:1px的2px的2px的#BDBDBD;
            边框:1px的固体#D1D1D1;>
       < / IMG>
    &所述; / A>
< / DIV>

隐藏文件code:

 保护无效chbindustry_SelectedIndexChanged(对象发件人,EventArgs的发送)
{
    如果(结果==假)
    {
        字符串[] = subdirectoryEntries Directory.GetDirectories(使用Server.Mappath(BusinessCards));
        串f;
        字符串[] SS;
        弦面= chklist.SelectedValue; // RadioButtonList1.SelectedValue;
        的foreach(在chbindustry.Items列表项LI)
        {
            如果(li.Selected)
            {                SS = li.Text.Split('(');                F =使用Server.Mappath(BusinessCards)的ToString()+\\\\+ SS [0];
                INT C = f.Count();
                DirectoryInfo的D =新DirectoryInfo的(F);
                。INT LEN = d.GetFiles()长;
                的for(int i = 1; I< = d.GetFiles()长/ 3;我++)
                {
                    Page.ClientScript.RegisterArrayDeclaration(ImgPaths,'+BusinessCards /+ f.Remove(0,f.LastIndexOf(\\\\')+ 1)+/+ 1 +.JPG') ;
                    Page.ClientScript.RegisterArrayDeclaration(参考文献,'+DesignBCs.aspx?IMG = BusinessCards /+ f.Remove(0,f.LastIndexOf(\\\\')+ 1)+/+ I + &放大器;侧=+端+');
                }
            }
        }
    }
    结果=真;
}

动态创建DIV:

 <脚本类型=文/ JScript的>
    $(文件)。就绪(函数(){        对于(VAR I = 0; I< ImgPaths.length; I = I + 3){
            VAR rowdiv ='< D​​IV ID =行>';
            rowdiv = rowdiv +'< D​​IV ID =细胞级=BOX2>';
            rowdiv = rowdiv +'< A HREF =+参考文献[I] +'>< IMG WIDTH =260px的风格=的box-shadow:1px的2px的2px的#BDBDBD;边界:1px的固体#D1D1D1; 高度=135​​pxALT =SRC ='+ ImgPaths [I] +'>&下; / IMG>&下; / A> ';
            rowdiv = rowdiv +'< / DIV>';
            rowdiv = rowdiv +'< D​​IV ID =细胞级=BOX2>';
            rowdiv = rowdiv +'< A HREF =+参考文献[I + 1] +'>< IMG WIDTH =260px的风格=的box-shadow:1px的2px的2px的#BDBDBD;边界:1px的固体# D1D1D1;高度=135​​pxALT =SRC ='+ ImgPaths第[i + 1] +'>&下; / IMG>&下; / A>';
            rowdiv = rowdiv +'< / DIV>';
            rowdiv = rowdiv +'< D​​IV ID =细胞级=BOX2>';
            rowdiv = rowdiv +'< A HREF =+裁判第[i + 2] +'>< IMG WIDTH =260px的风格=的box-shadow:1px的2px的2px的#BDBDBD;边界:1px的固体# D1D1D1;高度=135​​pxALT =SRC ='+ ImgPaths第[i + 2] +'>&下; / IMG>&下; / A>';
            rowdiv = rowdiv +'< / DIV>';
            rowdiv = rowdiv +'< / DIV>';
            $(#表)追加(rowdiv);
        }
    });
< / SCRIPT>


解决方案

如果你不介意使用JQuery,这会为你工作。
请参见

  $(文件)。就绪(函数(){
    $('IMG [SRC =未定义]')删除()。
});

演示删除DIV。

  $('IMG [SRC =未定义]')父()父()删除()。;

I am trying to select folder content.This folder contain images when I am selecting that folder it will select all content.plus it is taking img src undefind. so I need to remove that how can I remove if src is undefined using asp.net c#

<div id="cell" class="box2">
    <a href="undefined">
        <img width="260px" height="135px" src="undefined"
            alt="" 
            style="box-shadow: 1px    2px 2px #BDBDBD;
            border: 1px solid #D1D1D1;">
       </img>
    </a>
</div>

Code behind file:

protected void chbindustry_SelectedIndexChanged(object sender, EventArgs e)
{
    if (result == false)
    {
        string[] subdirectoryEntries = Directory.GetDirectories(Server.MapPath("BusinessCards"));
        string f;
        string[] ss;
        string side = chklist.SelectedValue;// RadioButtonList1.SelectedValue;
        foreach (ListItem li in chbindustry.Items)
        {
            if (li.Selected)
            {

                ss = li.Text.Split('(');

                f = Server.MapPath("BusinessCards").ToString() + "\\" + ss[0];
                int c = f.Count();
                DirectoryInfo d = new DirectoryInfo(f);
                int len = d.GetFiles().Length;
                for (int i = 1; i <= d.GetFiles().Length / 3; i++)
                {
                    Page.ClientScript.RegisterArrayDeclaration("ImgPaths", "'" + "BusinessCards/" + f.Remove(0, f.LastIndexOf('\\') + 1) + "/" + i + ".jpg'");
                    Page.ClientScript.RegisterArrayDeclaration("refs", "'" + "DesignBCs.aspx?img=BusinessCards/" + f.Remove(0, f.LastIndexOf('\\') + 1) + "/" + i + "&Side=" + side + "'");
                }
            }
        }
    }
    result = true;
}

Dynamically creating div:

<script type="text/jscript">
    $(document).ready(function () {

        for (var i = 0; i < ImgPaths.length; i = i + 3) {
            var rowdiv = '<div id="row">';
            rowdiv = rowdiv + ' <div id="cell" class="box2">';
            rowdiv = rowdiv + ' <a href="' + refs[i] + '"><img width="260px" style="box-shadow: 1px 2px 2px #BDBDBD; border: 1px solid #D1D1D1;" height="135px" alt="" src="' + ImgPaths[i] + '"></img></a> ';
            rowdiv = rowdiv + ' </div>';
            rowdiv = rowdiv + ' <div id="cell" class="box2">';
            rowdiv = rowdiv + '  <a href="' + refs[i + 1] + '"><img width="260px" style="box-shadow: 1px 2px 2px #BDBDBD; border: 1px solid #D1D1D1;" height="135px" alt="" src="' + ImgPaths[i + 1] + '"></img></a>';
            rowdiv = rowdiv + '</div>';
            rowdiv = rowdiv + ' <div id="cell" class="box2">';
            rowdiv = rowdiv + ' <a href="' + refs[i + 2] + '"><img width="260px" style="box-shadow: 1px 2px 2px #BDBDBD; border: 1px solid #D1D1D1;" height="135px" alt="" src="' + ImgPaths[i + 2] + '"></img></a>';
            rowdiv = rowdiv + '</div>';
            rowdiv = rowdiv + '</div>';
            $("#table").append(rowdiv);
        }
    });
</script>
解决方案

If you don't mind using JQuery, this would work for you.See DEMO HERE

$(document).ready(function () {
    $('img[src="undefined"]').remove();
});

Updated DEMO to remove div.

$('img[src="undefined"]').parent().parent().remove();

这篇关于如何删除dynamicaly创建&LT; D​​IV&GT;如果标记IMG SRC =在asp.net C#“未定义”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:26