to display images in gridview.you have to do the following
in button click just paste the following code
string strSql = "Select ImageId, ImageName, Images, ImageType, ImageSize from Pictures"; SqlDataAdapter daPics = new SqlDataAdapter(strSql, con); daPics.Fill(dsPics); dsPics.Tables[0].Columns.Add("imgFile"); foreach (DataRow drPics in dsPics.Tables[0].Rows) { drPics["imgFile"] = ("grabpicture.aspx?ImageId=" + drPics[0]); } gvWithImages.DataSource = dsPics; gvWithImages.DataBind();
in the above code pictures table is used and its design script is attached.you can find it in the attachment.
and i have used one more aspx page to load the image that is "grabpicture.aspx"
in grabpicture.aspx page global declaration area declare these variables
DataSet dsPics; SqlDataAdapter daPics; byte[] ImgContent; DataRow drPics; string strSql, strImgContentType; SqlConnection con = new SqlConnection("user id=<user>;pwd=<password>;data source=<sysname/ipaddress>;database=<dbname>");
in grabpicture.aspx page load event write the following code strSql = "Select * from Pictures where ImageId = " + Request.QueryString["ImageId"]; daPics = new SqlDataAdapter(strSql, con); dsPics = new DataSet(); daPics.Fill(dsPics); drPics = dsPics.Tables[0].Rows[0]; ImgContent = (byte[])drPics["Images"]; strImgContentType = drPics[3].ToString(); Response.ContentType = strImgContentType; Response.OutputStream.Write(ImgContent, 0, (int)drPics[4]); Response.End();
happy coding
regards, Muralidhar.
AttachmentsDisplaying Images in GridView (21633-332-Pictures.sql)
|
| Author: Surendra 23 Sep 2009 | Member Level: Bronze Points : 0 |
nice code Muralidhar
|