更新时间:2022-11-05 13:22:21
图像将存储在数据库中,您可以将数据库与gridview绑定
要上传图片,请使用FileUpload Control
The image will be store in database and you can bind the database with gridview
to upload an image take FileUpload Control
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
string filename = FileUpload1.FileName;
string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".JPG" || fileExt == ".GIF" || fileExt == ".png" || fileExt == ".jpeg")
{
FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\ThoughtForDay\\" + filename));
string path = "~\\ThoughtForDay\\" + filename;
SqlCommand cmd = new SqlCommand("Insert into ThoughtFortheDay(Imageurl,date1,date2) values('" + path + "',@date1,@date2)", cnn);
cmd.Parameters.AddWithValue("Imageurl",fileExt);
cmd.Parameters.AddWithValue("date1", txtdate1.Text);
cmd.Parameters.AddWithValue("date2", txtdate2.Text);
cmd.CommandType = CommandType.Text;
cnn.Open();
cmd.ExecuteNonQuery();
lblinfo.Text = "Uploaded Successfully";
cnn.Close();
}
else
{
lblinfo.Text = "Browse Only jpg,gif,bmp,png,jpeg Image File!";
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
ThoughtForDay是图像的名称.
在gridview中显示图像,请参见
在GridView中显示图像
在GridView中播放图像
ThoughtForDay is foledr name for images.
to show image in gridview see
Displaying Images in a GridView
isplaying Images in a GridView
也可以尝试