Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 从字段数据库路径检索到datagrid的映像_Asp.net_Visual Studio_Datagrid - Fatal编程技术网

Asp.net 从字段数据库路径检索到datagrid的映像

Asp.net 从字段数据库路径检索到datagrid的映像,asp.net,visual-studio,datagrid,Asp.net,Visual Studio,Datagrid,我需要把logo团队放在团队名称旁边,我有一个带有团队名称的表和一个名为logo的字段,如何直接从存储在表中字段中的路径检索存储在文件夹图像中的logo, 我分享一张我的桌子的图片,以便各位专家给我一个如何实现这一目标的方向! 当做 这是我的示例代码。dataGridView1是DataGridView控件 public partial class Form1 : Form { public ObservableCollection<Person> Persons { get

我需要把logo团队放在团队名称旁边,我有一个带有团队名称的表和一个名为logo的字段,如何直接从存储在表中字段中的路径检索存储在文件夹图像中的logo, 我分享一张我的桌子的图片,以便各位专家给我一个如何实现这一目标的方向! 当做
这是我的示例代码。dataGridView1是DataGridView控件

public partial class Form1 : Form
{
    public ObservableCollection<Person> Persons { get; set; }
    public Form1()
    {
        InitializeComponent();
        var Persons = new ObservableCollection<Person>();

        Persons.Add(new Person(1, "John", 5));
        Persons.Add(new Person(2, "Ed", 4));
        Persons.Add(new Person(3, "Sara", 3));
        dataGridView1.DataSource = Persons;
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
}

public class Person
{
    public int Rank { get; set; }
    public string Name { get; private set; }
    public int Score { get; set; }
    public Image Star { get; set; }

    public Person(int rank, string name, int score)
    {
        Rank = rank;
        Name = name;
        Score = score;
        Star = DrawStarImage(score);
    }
    private Image DrawStarImage(int starCount)
    {
        var starIcon = Image.FromFile("E:\\temp\\download.jpg");

        // the image of all stars (the width has to be the width of one star multiplied by the count of stars)
        var image = new Bitmap(starCount * starIcon.Width, starIcon.Height);

        using (var g = Graphics.FromImage(image))
        {
            for (int i = 0; i < starCount; i++)
            {
                // place the star icon to its position in the loop
                int x = (i * starIcon.Width);

                // https://msdn.microsoft.com/de-de/library/dbsak4dc(v=vs.110).aspx
                g.DrawImage(starIcon, x, 0, starIcon.Width, starIcon.Height);
            }

            g.Flush();
        }
        return image;
    }
}
公共部分类表单1:表单
{
公共可观察集合人员{get;set;}
公共表格1()
{
初始化组件();
var Persons=新的可观察集合();
增加(新的人(1,“约翰”,5));
增加(新的人(2,“Ed”,4));
增加(新的人(3,“Sara”,3));
dataGridView1.DataSource=个人;
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
}
公共阶层人士
{
公共整数秩{get;set;}
公共字符串名称{get;private set;}
公共整数分数{get;set;}
公共映像星形{get;set;}
公众人物(整数排名、字符串名称、整数分数)
{
秩=秩;
名称=名称;
分数=分数;
Star=DrawStarImage(分数);
}
私有映像DrawStarImage(int starCount)
{
var starIcon=Image.FromFile(“E:\\temp\\download.jpg”);
//所有星星的图像(宽度必须是一颗星星的宽度乘以星星数)
var image=新位图(starCount*starIcon.Width,starIcon.Height);
使用(var g=Graphics.FromImage(image))
{
对于(int i=0;i
在asp.net中,在数据网格中显示图像非常简单

 <asp:TemplateField  HeaderText="IMAGE"  ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                        <asp:Image ID="img" ImageUrl='<%#(Eval("IMAGE"))%>'  runat="server" Width="40px" Height="50px" CssClass="pic zoom" />
                    </ItemTemplate>

                </asp:TemplateField>

它是输出图像


我需要将徽标放入数据网格中!图像数据网格中的列类型是什么?它是**varchar**我需要datagrid读取具有正确语法的路径来检索图像!Datagrid不会根据路径自动渲染图像。相反,您需要根据来自数据库的路径绑定图像。