本文介绍了DataGridView图像详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何显示WinGrid的DataGridView图像详细信息.
图片
SQL数据库
Hi,
How to display DataGridView Image Details winform.
Image
SQL Data Base
ID:1001
Image(Photo):image
Name:aaa
Age:25
Gender:M
Time:9.30 am
ID:1002
Image(Photo):image
Name:bbb
Age:26
Gender:M
Time:9.31 am
ID:1003
Image(Photo):image
Name:ccc
Age:26
Gender:M
Time:9.30 am
在DataGridView中像这样显示
In DataGridView Like that show
1001 [Image] 25 M
aaa
9.30 am
1002 [Image] 26 M
bbb
9.31 am
1003 [Image] 26 M
ccc
>9.30 am
问候,
Karthikeyan,
班加罗尔.
Regards,
Karthikeyan,
Bangalore.
推荐答案
<asp:GridView runat="server" DataKeyNames="imageid" ID="Gridview1">
<Columns>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<img src="ImageRetrive.aspx?imageid=<%# Eval("imageid") %>" height="200px" width="200px" alt="Available" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
将以下内容写入imageRetrive.aspx的page_load
Write the below in the page_load of imageRetrive.aspx
protected void Page_Load(object sender, EventArgs e)
{
int imageid = int.Parse(Request.QueryString["imageid"].ToString());
string ConnString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
byte[] byeteArray = new byte[5000];
using (SqlConnection con = new SqlConnection(ConnString))
{
using (SqlCommand cmd = new SqlCommand("select myimage from storeimages where imageid="+imageid, con))
{
con.Open();
byeteArray = (byte[])cmd.ExecuteScalar();
Response.BinaryWrite(byeteArray);
con.Close();
}
}
}
SqlConnection conn = new SqlConnection("connection string");
conn.Open();
string get = "select * from Table1";
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = get;
cmd.Connection = conn;
da.SelectCommand = cmd;
DataSet ds = new System.Data.DataSet();
da.Fill(ds);
byte[] img = null;
//in my case the fourth column has an image
img = (byte[]) ds.Tables[0].Rows[0][3];
MemoryStream ms = new MemoryStream(img);
//for some reason this does not seem be creating a thumbnail
Image.GetThumbnailImageAbort cb = new Image.GetThumbnailImageAbort(ThumCallBack);
Image thumb = Image.FromStream(ms).GetThumbnailImage(10, 10, cb, IntPtr.Zero);
//theoretically, save the thumbnail back to the memory stream we opened above
thumb.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
//read it back into the img array
ms.Read(img, 0, img.Length);
//put it back in the dataset before we actually bind the data to the DataGridView
ds.Tables[0].Rows[0][3] = img;
dataGridView1.DataSource = ds.Tables[0];
...
public bool ThumCallBack()
{
return true;
}
希望这会有所帮助.
Hope this helps a bit.
这篇关于DataGridView图像详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!