如何显示标题相同的图像? [英] How to display images with the same title?

查看:51
本文介绍了如何显示标题相同的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个fileupload功能,用户可以上传图片并且可以正常工作。

问题是它在SQL中保存如下:



id ||路径||扩展||大小|| ContentType ||标题



1 || roses || .jpg || 11477 || Image / jpeg ||鲜花

2 ||郁金香|| .jpg || 11477 || Image / jpeg ||鲜花

2 ||康乃馨|| .jpg || 11477 || Image / jpeg ||鲜花



所以它将文件保存在很多列中...



我有gridview,如果选择一行并单击它,它将根据单击的行加载所有详细信息。

我需要一个代码/功能,它会根据标题显示所有图像。

因此,如果人们选择一行并且标题是folwers(如上所述)它应该加载标题=鲜花的所有图像。



我尝试过:



I have multiple fileupload function where users can upload Pictures and it works.
The Problem is it gets save in SQL like this:

id|| Path ||Extension||Size ||ContentType ||Title

1 ||roses ||.jpg || 11477 || Image/jpeg || flowers
2 ||tulips ||.jpg || 11477 || Image/jpeg || flowers
2 ||carnations||.jpg || 11477 || Image/jpeg || flowers

So it saves the files in many columns...

I have gridview and if select a row and click on it, it will load all the Details based on the clicked row.
And I Need a Code/function that will Show me all the Images based on the title.
So if People choose a row and the title is folwers(like above) it should load all the Images with the title = flowers.

What I have tried:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
           {
               GridView listBox = sender as GridView;
               int selectedID =  Int32.Parse(listBox.SelectedDataKey.Value.ToString());
               string titel = listBox.SelectedRow.Cells[1].Text;
               LoadDetail(selectedID, titel);
           }







void LoadDetail(int id, string titel)
            {

                    List<pic> sb = (from x in myEnt.Pic where (x.ID == id) && (x.Titel == titel) select x).ToList();

                    lblTitel.Text = String.Join(", ", sb.Select(x => x.Titel));
                    Img1.ImageUrl = "data:Image/jpg;base64," + String.Join(", ", sb.Select(x => Convert.ToBase64String((byte[])x.FileContent)));

}

//它只显示第一张图片。

// it only Shows the first Picture.

推荐答案

你的清单只有一个条目,因为你正在使用ID作为选择标准。要获得多个匹配,请使用:

Your list has only one entry because you are using the ID as select criteria. To get multiple matches use:
List<pic> sb = (from x in myEnt.Pic where x.Titel == titel) select x).ToList();



但是你有迭代列表项。所以我将创建两个新函数,如 LoadMatchingTitle(字符串标题) LoadMatchingImageType(字符串类型)然后迭代结果并将其显示在新的网格视图中或更新现有的视图。


But then you have to iterate over the list items. So I would create two new functions like LoadMatchingTitle(string titel) and LoadMatchingImageType(string type) which then iterate over the results and displays them in a new grid view or update the existing one.


这篇关于如何显示标题相同的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆