C# 网格视图显示图像

C# 网格视图显示图像,c#,image,gridview,C#,Image,Gridview,我的数据库中有一个ActivityType字段。数值为[1,2,3]。 每个数字代表活动的类型。 我想将gridview中的类型显示为图像 我有3张照片 活动类型1=avtivity_choise.jpg 活动类型2=活动\u text.jpg 活动类型3=activity\u count.jpg 我已经尝试使用模板字段执行此操作,但我需要switch case语句将数字传输到图像url…您可以处理此事件。使用类似以下内容: void gridView_RowDataBound(Object

我的数据库中有一个ActivityType字段。数值为[1,2,3]。 每个数字代表活动的类型。 我想将gridview中的类型显示为图像

我有3张照片

  • 活动类型1=avtivity_choise.jpg

  • 活动类型2=活动\u text.jpg

  • 活动类型3=activity\u count.jpg

我已经尝试使用模板字段执行此操作,但我需要switch case语句将数字传输到图像url…

您可以处理此事件。使用类似以下内容:

void gridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{

   if(e.Row.RowType == DataControlRowType.DataRow)
   {
       int type = int.Parse(e.Row.Cells[typeCellIndex].Text);
       Image img = (Image) e.Row.Cells[imageCellIndex].FindControl(imageID);
       switch type
       {
          case 1:
          {
             img.ImageUrl = "avtivity_choise.jpg";
          }
          ......
       }

   }

 }
还可以将图像字段绑定到数据库字段。请参阅以下内容:

void gridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{

   if(e.Row.RowType == DataControlRowType.DataRow)
   {
       int type = int.Parse(e.Row.Cells[typeCellIndex].Text);
       Image img = (Image) e.Row.Cells[imageCellIndex].FindControl(imageID);
       switch type
       {
          case 1:
          {
             img.ImageUrl = "avtivity_choise.jpg";
          }
          ......
       }

   }

 }


您指的是哪种类型的GridView?WPF(
System.Windows.Controls
)、Windows窗体(
System.Windows.Forms
)和ASP.NET(
System.Web.UI.WebControls
)有GridView。正在尝试在此处获取我的问题的答案。我有两个图像,我想显示在一个网格,其中列出了学生。其中一个图像将根据学生是否注册而显示,我的视图是强类型的,如何才能使其工作?