如何按标题分组数据?

时间:2016-11-24 11:48:20

标签: c# gridview binary selected

我有一个SQL表:



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




我想在一行中显示所有具有相同标题的图片。 例如,标题花包含图片等

我也有一个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>
&#13;
&#13;
&#13;

所以我的目标是选择一行然后点击它。如果所选行的标题是&#34; flower&#34;它应该加载2个图像。

我已经做过什么/尝试

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

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

它只显示一张图片,(因为所选的ID),但我也不知道如何提及标题。提前谢谢!

1 个答案:

答案 0 :(得分:0)

尝试在DataKeys中使用这两列:

DataKeyNames="ID,Title">

var id = listBox.DataKeys[listBox.SelectedIndex].Values["ID"];
var title = listBox.DataKeys[listBox.SelectedIndex].Values["Title"];