Hi...
!st create a Images folder to ur project. Then
for images are saved in folder abd its path insertered in database.
In aspx:
<asp:FileUpload ID="imgful" runat="server" Height="25px" style="font-weight: 700" />
<asp:button id="btnimg" runat="server" text="SaveProduct" onclick="btnimg_Click" xmlns:asp="#unknown"> ForeColor="DeepPink" style="font-weight: 700" Width="99px" Height="28px"/> </asp:button>
In aspx.cs:
protected void btnimg_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(imgful.PostedFile.FileName);
imgful.SaveAs(Server.MapPath("~/Images/" + filename));
con = new MySqlConnection(cs);
con.Open();
cmd = new MySqlCommand("Insert into Items(ProductName,ImageUrl) values(@ImageName,@ImagePath)", con);
cmd.Parameters.AddWithValue("@ImageName", filename);
cmd.Parameters.AddWithValue("@ImagePath", "~/Images/" + filename);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
for retriving images and am displaying in gridview
In button_click:
con = new MySqlConnection(cs);
con.Open();
cmd = new MySqlCommand("select * from Items", con);
cmd.ExecuteNonQuery();
da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
gdimg.DataSource = ds;
gdimg.DataBind();
gdimg.Visible = true;
May its useful to u. Thank u.