01/10/2018, 10:56
Cần giúp đỡ về resize ảnh khi upload C#
Code dưới đây em đã thêm dc vào DB và show được lên gridview rồi. nhưng show lên thì ảnh to đúng, giữ nguyên size gốc. GIờ em muốn resize cho vừa đẹp để hiển thị lên gridview trong webform ạ
Thanks~~
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void btnadd_Click(object sender, EventArgs e)
{
SqlDsSanpham.InsertParameters["id_sanpham"].DefaultValue = txtid_sanpham.Text;
SqlDsSanpham.InsertParameters["id_danhmuc"].DefaultValue = DV1.SelectedValue;
SqlDsSanpham.InsertParameters["ten_sanpham"].DefaultValue = txt_tensanpham.Text;
SqlDsSanpham.InsertParameters["img_sanpham"].DefaultValue = Upload.FileName.ToString();
SqlDsSanpham.InsertParameters["gia_sanpham"].DefaultValue = txt_giasanpham.Text;
SqlDsSanpham.InsertParameters["des_sanpham"].DefaultValue = txt_chitiet.Text;
string filename = Path.GetFileName(Upload.PostedFile.FileName);
Upload.SaveAs(Server.MapPath("~/images/" + filename));
try
{
SqlDsSanpham.Insert();
txtid_sanpham.Text = "";
DV1.Items.Add("--Chọn một danh mục--");
DV1.DataBind();
txt_tensanpham.Text = "";
txt_giasanpham.Text = "";
txt_chitiet.Text = "";
lblthongbao.Text = "Thêm thành công.<br/><br/>";
GridView1.DataBind();
lblthongbao.Text = "Thêm thành công.<br/><br/>";
}
catch (Exception ex)
{
lblthongbao.Text = "Một lỗi đã xảy ra, Vui lòng kiểm tra lại.<br/><br/>";
}
}
}
Bài liên quan