Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I have a gridview:

ASP.NET
<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>



C#
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:

C#
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);
           }


then I click on it it just Shows the one Picture, but in SQL there are 4 Picture saved with the same title....
Posted
Updated 21-Nov-16 5:23am
Comments
$*Developer - Vaibhav*$ 21-Nov-16 11:09am    
you need to create run time image control for binding images

code describe only one image control you are using (Img1.ImageUrl)

1 solution

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

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


The linq is getting only the First or the default, you need to select all of them, so I might make
C#
List<users>
and then you could use linq to retrieve all of them to a list

C#
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
 
Share this answer
 
v2
Comments
Member 12802669 22-Nov-16 5:57am    
I think that could work. I tried it but I dont know how to write the Labels.

lbltitle.Text = users.title; is not working anymore....
J. Calhoun 22-Nov-16 8:51am    
Well, now users is a list so you could do one of two things, add another listbox inside of your grid view that has an item source of users and that is bound to Title1, or you can iterate through users and assign a property per title.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900