如何按标题分组数据? [英] How to group data by title?

查看:73
本文介绍了如何按标题分组数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL表:

I have a 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 the Pictures with the same title in one row. So for example, the Title flowers contains to Pictures, etc.
I also have a gridview:




<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>





所以我的目标是它选择一行并单击它。如果所选行的标题是花,那么它应该加载2个图像。



我尝试过:





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:

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





它只显示一张图片,(因为所选的ID)但我不知道如何也提到了这个头衔。在此先感谢!



It only Shows one Picture, (because of the selected id) but I dont know how to mention the title too. Thanks in advance!

推荐答案

尝试使用where而不是id在where子句中使用Title

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













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
          }
}


您已经在如何显示具有相同标题的图像? [ ^ ]。



但是现在你已经删除了搜索对于标题并在查询中保留ID,而我建议从查询中删除ID而不是标题。



但即使这样它也可能不会k符合预期,因为您可能会得到多个结果。您希望它们如何在一行中显示?



常见的解决方案是提供某种过滤器控件,可用于仅加载选定的(匹配) )项目并在网格视图中显示它们。这可以通过单击特定单元格并将其用作过滤条件来实现,但需要另外一个控件来重置过滤器并重新加载所有数据。



我建议您在开始实现相关代码之前考虑这一点并定义数据应如何显示(使用可选的过滤)。
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.


这篇关于如何按标题分组数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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