Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a SQL table:
C#
ID || Title  || FileName || Extension || FileContent

1  || flower ||rose      || jpg       || binary data

2  || flower ||tulip     || jpg       || binary data

3  || cats   ||black-c   || png       || binary data

4  || cats   ||White-c   || jpg       || binary data

5  || Dogs   ||Brown-d   || jpg       || binary data


C#
I want to display all the Pictures with the same title in one row. So for example, the Title flowers contains to Pictures, etc.
I also have a gridview:

ASP.NET
<pre lang="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="Title" HeaderText="Title" SortExpression="Title" />
            <asp:BoundField DataField="FileName" HeaderText="FileName" SortExpression="FileName" />   
	    <asp:BoundField DataField="FileContent" HeaderText="FileContent" SortExpression="FileContent" visible="false" />       
       </Columns>
</asp:Gridview>


So my Goal is it to selected a row and click on it. If the Title of the selected row is "flower" than it should load the 2 Images.

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());
              LoadDetail(selectedID);
          }


C#
void LoadDetail(int id)
           {

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

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


It only Shows one Picture, (because of the selected id) but I dont know how to mention the title too. Thanks in advance!
Posted
Updated 24-Nov-16 1:11am
Comments
Jawad Ahmed Tanoli 24-Nov-16 6:59am    
in your table id is unique
List<pic> sb = (from x in myEnt.Pic where x.ID == id select x).ToList();
it will return you one row .so put title in where x.title=="flower"
Member 12802669 24-Nov-16 7:06am    
it is a gridview, so the title can also be dogs, cats,....
Jawad Ahmed Tanoli 24-Nov-16 7:16am    
if you want to display Group by Title
you can't put Group by in this table.title may be same but other fields are different you get every time all rows to show .

Try this instead of id use Title in where clause
C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
       {
           GridView listBox = sender as GridView;
           string title = GridView1.SelectedRow.Cells[1].Text;
           LoadDetail(title);
       }




C#
void LoadDetail(string title){
          List<pic> sb = (from x in myEnt.Pic where x.Tiltle == title select x).ToList();

          //Apply foreach loop in list
          foreach (var item in sb) {
              //add the images here and title on dynamic controls
          }
}
 
Share this answer
 
v2
Comments
Member 12802669 24-Nov-16 7:09am    
I also tried c.Title == tile. And if select a row and the title is for example flower than I will get flower, flowers. 2 times the title but not the to Images.

I also tried it like x.Filecontent = Title, but it is a binary Picture and I dont know how to write the Code for it.
I am really new at coding. What is dynamic Control?
You have already asked this at How to display images with the same title?[^] .

But now you have removed searching for the title and left the ID in the query while I suggested to remove the ID and not the title from the query.

But even then it might not work as expected because you may get multiple results. How would you want them to be displayed in a single row?

The common solution is to provide some kind of filter controls that can be used to load only selected (matching) items and show them in the grid view. This can be off course also implemented by clicking on a specific cell and using that as filter criteria but would require that there is another control to reset the filter and re-load all data.

I suggest that you should think about this and define how data should be displayed (with optional filtering) before starting to implement related code.
 
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