کد نمایش عکس (صفحه Image.ashx)
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["..."].ToString());
SqlCommand com = new SqlCommand("SELECT Thumbnail FROM Images WHERE (IdCollege =@IdCollege)", con);
com.Parameters.Add("@IdCollege",SqlDbType.Int).Value=context.Request.QueryString["IdCollege"];
con.Open();
byte[] image = (byte[])com.ExecuteScalar();
con.Close();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "image/gif";
context.Response.BinaryWrite(image);
کد Gridview (صفحه Gallery.aspx)
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Gallery/Image.ashx?IdCollege=0" PostBackUrl='<%# "~/Gallery/VeiwImage.aspx?IdImage="+ Eval("IdImage") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:... %>"
SelectCommand="SELECT [IdImage], [IdCollege], [Thumbnail] FROM [Images] WHERE ([IdCollege] = @IdCollege)">
<SelectParameters>
<asp
arameter DefaultValue="0" Name="IdCollege" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>