Click here to Skip to main content
15,913,275 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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


C#
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.
Posted
Updated 22-Nov-16 2:30am

1 solution

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

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.
 
Share this answer
 

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