如何在gridview中显示具有相同标题的SQL中的所有图像? [英] How to display all images from SQL with the same title in gridview?

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

问题描述

I have a gridview:




<asp:GridView ID="GridView1" CssClass="gridview" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDataBound="RowDataBound" Width="100%"  GridLines="None" SelectedRowStyle-BackColor="#a8c066" runat="server" AutoGenerateColumns="False" DataKeyNames="ID">
        <columns>
            <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" ReadOnly="True" Visible="false" />       
            <asp:BoundField DataField="Titel" HeaderText="Titel" SortExpression="Titel" />
            <asp:BoundField DataField="Path" HeaderText="Path" SortExpression="Path" />        
            <asp:BoundField DataField="extension" HeaderText="extension" SortExpression="extension" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" />
            <asp:BoundField DataField="ContentType" HeaderText="ContentType" SortExpression="ContentType" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" /> 
         

<SelectedRowStyle BackColor="#A8C066"></SelectedRowStyle>










there are many Pictures in SQL with the same title. I want that if you select a row and click on it, it will Show all the Images matching to the title of the selected row.
I tried this: 





我是什么尝试过:





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()); // this works!
              string titel = listBox.SelectedRow.Cells[1].Text;
              LoadDetail(selectedID, titel);
          }

           void LoadDetail(int id, string titel)
           {
               Users users = (from x in myEnt.Schwarzes_Brett where (x.ID == id) && (x.Titel == titel) select x).FirstOrDefault();

             lbltitle.Text = users.title;
             Img1.ImageUrl = "data:Image/jpg;base64," + Convert.ToBase64String((byte[])sb.FileContent);
           }





然后我点击它只显示一张图片,但在SQL中有4张使用相同标题保存的图片....



then I click on it it just Shows the one Picture, but in SQL there are 4 Picture saved with the same title....

推荐答案

目前看起来你正在从这段代码中获得标题。



Currently it looks like you are getting the title from this code.

Users users = (from x in myEnt.Schwarzes_Brett where (x.ID == id) && (x.Titel == titel) select x).FirstOrDefault();





linq只获得First或默认值,你需要选择所有这些,所以我可以制作



The linq is getting only the First or the default, you need to select all of them, so I might make

List<users>

然后你可以使用linq将它们全部检索到列表中



and then you could use linq to retrieve all of them to a list

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





然后对于该列表中的每个用户,您可以将图片添加到网格视图中



Then for each User in that list you could add the picture to your grid view


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

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