【问题标题】:grid view display image网格视图显示图像
【发布时间】:2011-05-08 06:19:01
【问题描述】:

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

我有 3 张图片

  • 活动类型 1 = avtivity_choise.jpg

  • 活动类型 2 = activity_text.jpg

  • 活动类型 3 = activity_count.jpg

我曾尝试使用模板字段这样做,但我需要 switch case 语句将数字传输到图像 url...

【问题讨论】:

  • 你指的是什么类型的GridView?有用于 WPF (System.Windows.Controls)、Windows 窗体 (System.Windows.Forms) 和 ASP.NET (System.Web.UI.WebControls) 的 GridView。

标签: c# image gridview


【解决方案1】:

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

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";
          }
          ......
       }

   }

 }

您还可以将图像字段绑定到数据库字段。参考以下:

http://msdn.microsoft.com/en-us/library/aa479350.aspx

http://csharpdotnetfreak.blogspot.com/2009/07/display-images-gridview-from-database.html

http://www.codeproject.com/KB/aspnet/imagegalleryingridview.aspx

【讨论】:

  • 试图在这里得到我的问题的答案。我有两张图片要显示在列出学生的网格中。将根据学生是否注册显示其中一张图片,我拥有的这个视图是强类型的,我怎样才能让它工作?
猜你喜欢
  • 2015-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多