DataGridView图像详细信息 [英] DataGridView Image Details

查看:82
本文介绍了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.

推荐答案

嗨. . .

这对于从数据库中检索图像,以显示在gridview中很有用

hi. . .

This will be useful to retrieve the image from database, to display in a gridview

<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();
           }
       }



   }


这不是完整的解决方案,但它会给您一个方向发展的想法.您将需要自己做一些工作以改进此代码,特别是要获得较小尺寸的图像以缩略图形式显示(这是您的练习).

This is not the full solution but it will give you an idea to move in a direction. You are gonna have to do some work yourself to improvise this code, particularly to get a small size of the image to display as a thumbnail (that''s an exercise for you).

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.


这是示例代码,只是作为您的常客尝试并自定义代码

http://forum.codecall.net/topic /70888-howto-display-image-from-datagridview-with-ms-access/#axzz29Mlzr7yY [ http://www.aspsnippets. com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx [
This Is Sample Code Just Try And Customize code As your Frequenter

http://forum.codecall.net/topic/70888-howto-display-image-from-datagridview-with-ms-access/#axzz29Mlzr7yY[^]

http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx[^]


这篇关于DataGridView图像详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆