I have Table named Product Have Fields as
Prod_ID int
Prod_Name varchar(50)
Price int
Image varchar(50)----save as url

I have form which have one DropDownList Having Boung To Prod_ID Coloum it shows all the data from prod_Id coloumn
and have one gridview...
if user selects prod_ID from dropdown then it should retrive Prod_Name, Price and Image from database for that particular prod_id and display it in Gridview....

Default.aspx looks as follows....

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            DataSourceID="SqlDataSource1" DataTextField="Prod_Id" DataValueField="Prod_Id">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:OnlineShopConnectionString %>" 
            SelectCommand="SELECT [Prod_Id] FROM [Product]"></asp:SqlDataSource>

        <asp:GridView ID="GridView1"
            runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

and Default.aspx.cs looks as follows....

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection();
        con.ConnectionString = "Data Source=HP-HP\\SQLEXPRESS;Initial Catalog=OnlineShop;Persist Security Info=True;User ID=sa;Password=rane@1234";
        con.Open();
        SqlCommand cmd = new SqlCommand("Select * from Product where Prod_Id='" + DropDownList1.Text + "'", con);
        SqlDataReader dr = cmd.ExecuteReader();

            GridView1.DataSource = dr;
            GridView1.DataBind();

    }

}









    When user selects dropdownlist value it displays the record but instead of image it shows me image url......

Replace the gridview code with the following code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false>
    <columns>
        <asp:TemplateField HeaderText="Image Column">
            <ItemTemplate>
                <img src='<%#Eval("Image")%>' alt="display image"/>
            </ItemTemplate>
        </asp:TemplateField>
    </columns>
</asp:GridView>
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.