日期:2014-05-17  浏览次数:21060 次

dataGridView1的超链接显示图片
dataGridView1 图片列的超链接 直接显示图片
超链接地址:c:\jkd.jpg

------解决方案--------------------
说的详细一点
------解决方案--------------------
使用模板列,并使用Image控件来显示你的图片地址

<ItemTemplate>
<img src='<%# Eval("imgurl") %>'
</ItemTemplate> 

或是参考下面:
http://social.microsoft.com/Forums/zh-CN/visualcshartzhchs/thread/bc682f72-33ce-4841-97e3-8a859bcea3bb
------解决方案--------------------
C# code

        private void demoGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (demoGrid.Columns[e.ColumnIndex].Name.Equals("Image"))
            {
                string path = System.Windows.Forms.Application.StartupPath + @"/1.gif";
                e.Value = GetImage(path);
            }
        }

 public System.Drawing.Image GetImage(string path)
        {
            System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
            System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
            fs.Close();
            return result;
        }

------解决方案--------------------
模版列的使用,在模版列中使用<a href='<%# ~/imgpath/Eval("img") #'>img</a>将连接绑定好!
------解决方案--------------------