I have a sql table
Icon(ID(int),SUBCAT_ID, ALBUM_ID, SUBCAT_NAME, ALBUM_NAME, ICON_IMAGE(image), ICON_SIZE, BLACKWHITE, NAME, DESIGNER, HITS, RATINGS)
I have a gallery.aspx page which have a listview that is showing the images of the icon the code looks like this.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID"
DataSourceID="SqlDataSource1" GroupItemCount="3"
onselectedindexchanged="ListView1_SelectedIndexChanged">
<GroupTemplate>
<tr ID="itemPlaceholderContainer" runat="server">
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<SelectedItemTemplate >
<asp:ImageButton ID="ImageButton1" runat="server" style="display:inline;float:left;margin:10px;border: 1px solid rgb(204, 204, 204);padding:5px;padding-bottom:10px; height:150px;width:150px;"
ImageUrl='<%# "Handler.ashx?ID=" + Eval("ID")%>'/>
<br />
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
<br />
</SelectedItemTemplate>
<ItemTemplate>
<td id="Td5" runat="server" style="background-color: #E0FFFF; color: #333333;">
<asp:ImageButton ID="ImageButton1" runat="server" style="display:inline;float:left;margin:10px;border: 1px solid rgb(204, 204, 204);padding:5px;padding-bottom:10px; height:150px;width:150px;"
ImageUrl='<%# "Handler.ashx?ID=" + Eval("ID")%>'/>
<br />
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
<br />
</td>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td6" runat="server">
<table ID="groupPlaceholderContainer" runat="server" border="1"
style="background-color: #FFFFFF; border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px; font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td7" runat="server"
style="text-align: center; background-color: #5D7B9D; font-family: Verdana, Arial, Helvetica, sans-serif; color: #FFFFFF">
<asp:DataPager ID="DataPager1" runat="server" PageSize="12">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ICOBANKConnectionString %>"
SelectCommand="SELECT [ICON_IMAGE], [ID] FROM [Icon]"></asp:SqlDataSource>
I'm retreiving the images from the sql table using the handler.ashx this code looks like this
public void ProcessRequest(HttpContext context)
{
Int32 picid;
if (context.Request.QueryString["id"] != null)
picid = Convert.ToInt32(context.Request.QueryString["id"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = ShowAlbumImage(picid);
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
}
public Stream ShowAlbumImage(int picid)
{
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ICOBANKConnectionString"].ConnectionString;
SqlConnection connection = new SqlConnection(conn);
string sql = "SELECT ICON_IMAGE FROM Icon WHERE (ID = @ID)";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@ID", picid);
connection.Open();
object img = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
finally
{
connection.Close();
}
}
I have another page icondetailpage.aspx that have detail of the icons. I'm facing two problems one is to get the id of the icon image that is stored in the database that will be used in icondetailpage.aspx to fetch data. Second problem that i'm facing is to increase the hits that is stored in the table. Kindly guide me
1. how do i get the ID of the icon image?
2. How do I increase the hits?