How to group data by name?

I have an SQL table:

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 

I want to display all images with the same caption on the same line. So, for example, the color of the inscription contains images, etc.

I also have 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="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 to select a row and click on it. If the title of the selected line is a "flower", it should load 2 images.

WHAT I ALREADY ACT / TRENAL

  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { GridView listBox = sender as GridView; int selectedID = Int32.Parse(listBox.SelectedDataKey.Value.ToString()); LoadDetail(selectedID); } 

  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 shows only one image (due to the selected identifier), but I do not know how to mention the name. Thanks in advance!

+6
source share
1 answer

Try using both columns in DataKeys:

 DataKeyNames="ID,Title"> var id = listBox.DataKeys[listBox.SelectedIndex].Values["ID"]; var title = listBox.DataKeys[listBox.SelectedIndex].Values["Title"]; 
0
source

Source: https://habr.com/ru/post/1012628/


All Articles