|
|
|
แสดง รูปใน GridView ค่ะ โดยเขียนให้โค๊ดที่ RowDataBound คะ Asp.net C# |
|
|
|
|
|
|
|
แทรก Image ใน GridView แล้วหรือยังครับ
Code (C#)
Image imgView = (Image)(e.Row.FindControl("imgViewIcon"));
if (imgView != null)
{
imgView.ImageURL = Server.MapPath("/upload/icon.gif");
}
|
|
|
|
|
Date :
2013-02-13 11:30:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
imgView.ImageURL = Server.MapPath("/upload/icon.gif");
รูปไม่ขึ้นค่ะ
|
|
|
|
|
Date :
2013-02-13 12:26:06 |
By :
mushroomsn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug ดูครับ มันเข้าเงื่อนไขนี้หรือเปล่าครับ มันอาจจะ FindControl หา Image Control ไม่เจอครับ
|
|
|
|
|
Date :
2013-02-13 14:38:08 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ BoundField
GetPokemon.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetPokemon.aspx.cs" Inherits="GetPokemon" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
GetPokemon.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class GetPokemon : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BoundField Icon = new BoundField();
Icon.HeaderText = "Icon";
BoundField Code = new BoundField();
Code.HeaderText = "Code";
Code.DataField = "PokemonCode";
BoundField Name = new BoundField();
Name.HeaderText = "Pokemon";
Name.DataField = "PokemonName";
BoundField Pic = new BoundField();
Pic.HeaderText = "Picture";
GridView1.Columns.Add(Icon);
GridView1.Columns.Add(Code);
GridView1.Columns.Add(Name);
GridView1.Columns.Add(Pic);
}
PokedexTable pokemon = new PokedexTable();
GridView1.AutoGenerateColumns = false;
GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
GridView1.DataSource = pokemon.GetAllPokedex();
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image Icon = new Image();
Icon.ImageUrl = string.Format("~/PokemonImage.aspx?type=icon&code={0}", e.Row.Cells[1].Text);
e.Row.Cells[0].Controls.Add(Icon);
Image Pic = new Image();
Pic.ImageUrl = string.Format("~/PokemonImage.aspx?type=artwork&code={0}", e.Row.Cells[1].Text);
e.Row.Cells[3].Controls.Add(Pic);
}
}
}
|
|
|
|
|
Date :
2013-02-13 16:26:28 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mr win ค่ะ
debug แล้วค่ะ
Image1.ImageUrl "C:\\Documents and Settings\\Administrator\\Desktop\\Program\\test\\test\\images\\down.gif"
|
|
|
|
|
Date :
2013-02-13 17:10:27 |
By :
mushroomsn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|