Click here to Skip to main content
15,899,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.NET
<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

C#
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?
Posted
Comments
Harshil_Raval 22-Oct-13 5:47am    
I don't get you. Do you want to get id of icon? I think you want to use it in listview but do not want to display it? If yes, then use hiddenfield in listview and bind id to it.
About icon hits, use onItemCommand event of listview to get selected icon id which is inside hiddenfield and accordingly fire db query to plus icon visit.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900