[英]How to remove dynamicaly created <div> tag if img src='undefined' in asp.net C#?
[英]How to remove undefined array in asp.net?
所以我需要删除如果使用asp.net c#未定义src该如何删除
<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>
文件后面的代码:
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;
}
假设您有C#中图像src值的列表,则可以使用LINQ过滤掉未定义的任何一个:
var list = some code to get a list of img srcs from your folder;
list = list.Where(value => !string.IsNullOrWhitespace(value)).ToList();
Lambda value => !string.IsNullOrWhitespace(value)
过滤list
,以使每个元素都不为null或空格(我假设您的意思是未定义)。
这有帮助吗? 如果您可以分享自己拥有的一些示例代码,我们可以提供更多帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.