Makjain 0 Newbie Poster

On the selection of value from dropdownlist, image is displayed in display page. Selectedvalue has many image in DB say 50+ but as per my query below it reads only 1st image of DB i.e.1st image of database. So do let me know where my code is gng wrong.

CODE VIEW OF DISPLAY PAGE:

public string FormatURL(object strArgument)
    {
        return ("Read.aspx?Coins=" + strArgument);
    }

SOURCE VIEW OF DISPLAY PAGE:

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> 
<ItemTemplate>

Image:<asp:Image ID="Image1" runat="server" Height="50px" Width="100px" imageUrl='<%#FormatURL(DataBinder.Eval(Container.DataItem, "coins")) %>'/>

</ItemTemplate>

</asp:DataList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CoinsString %>" 

SelectCommand="SELECT [imgdata], [imgtype], [Coins] FROM [TABLE] WHERE ([Coins] = @Coins)">

<SelectParameters>

<asp:ControlParameter ControlID="DropDownList1" Name="Coins" PropertyName="SelectedValue" Type="String" />

</SelectParameters>

</asp:SqlDataSource>

CODE VIEW OF READ PAGE:

protected void Page_Load(object sender, EventArgs e)
    {
        string strImageID = Request.QueryString[0];
        SqlConnection cn = new SqlConnection("Data Source=MAKJAIN;Initial Catalog=DATABASE;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("select imgtype,imgdata from TABLE where coins='" + strImageID + "' ", cn);
        //
        try
        {
            cn.Open();
            SqlDataReader dr;
            dr = cmd.ExecuteReader();
            while (dr.Read())
            //yup we found our image
            {
                //retrving the image content type                
                Response.ContentType = dr["imgtype"].ToString();
                //displaying the image                
                Response.BinaryWrite((byte[])dr["imgdata"]);
            }
            cn.Close();
        }
        catch
        {
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.