I am working on a ShoppingCart....
I am keeping it simple ....
I have One DropDownList Product_Id whose values r retrived from database....
My Table have Following Fields...
Product_ID
Product_Name
Price
Image
So whenever user seelects a product_id from dropdownlist thats value gets added to the gridview which will display all fields.....
My Code Is As Follows
SqlConnection con;
SqlCommand cmd;
static DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack != true)
{
Label1.Text = "";
dt.Columns.Add("Prod_Id");
dt.Columns.Add("Prod_Name");
dt.Columns.Add("Price");
dt.Columns.Add("Image");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataRow row;
int x = int.Parse(DropDownList1.Text);
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();
cmd = new SqlCommand("Select * from Product where Prod_Id='" + x + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
DataRow r = dt.NewRow();
r[0]= dr[0];
r[1] = dr[1];
r[2] = dr[2];
r[3]=dr[3];
dt.Rows.Add(r);
}
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
i am using PostBack to check wheather the load is fresh or not if its fresh then the user have to fill cart from starting else the products get added to gridview...
Now the problem is that i am not able to retrive image from database insted its showing the path of that image....