GridView怎样根据数据库中不同的值显示不同的图片
例如:数据库中“img”字段数据值为1的记录显示A图像,为2的记录显示B图像。
我现在用的是一个比较投机的方法,就是把图像名的与记录值名一样<asp:Image ID="img1" runat="server" Height="50px" Width="100px" ImageUrl='<%# Bind("img","images/{0}.jpg") %>' /></td>我想知道正常的方法,谢谢
例如:数据库中“img”字段数据值为1的记录显示A图像,为2的记录显示B图像。
我现在用的是一个比较投机的方法,就是把图像名的与记录值名一样<asp:Image ID="img1" runat="server" Height="50px" Width="100px" ImageUrl='<%# Bind("img","images/{0}.jpg") %>' /></td>我想知道正常的方法,谢谢
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
(e.Row.FindControl("Label2") as Label).Attributes.Add("onmouseover", "ShowDiv(this,'" + Convert.ToString(DataBinder.Eval(e.Row.DataItem, "RoomTypeId")) + "' ,'" + HiddenField1.Value + "','" + HiddenField2.Value + "','" + HiddenField3.Value + "')");
(e.Row.FindControl("Label2") as Label).Attributes.Add("onmouseout", "CloseDiv()");
int RoomState = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "RoomState"));
switch (RoomState)
{
case 1:
((Label)e.Row.FindControl("Label1")).Text = "充足";
(e.Row.FindControl("image") as Image).ImageUrl = "~/images/fan-3.gif";
break;
case 2:
((Label)e.Row.FindControl("Label1")).Text = "一般";
(e.Row.FindControl("image") as Image).ImageUrl = "~/images/fan-1.gif";
break;
case 3:
((Label)e.Row.FindControl("Label1")).Text = "紧张";
(e.Row.FindControl("image") as Image).ImageUrl = "~/images/fan-4.gif";
break;
case 4:
((Label)e.Row.FindControl("Label1")).Text = "客满";
(e.Row.FindControl("image") as Image).ImageUrl = "~/images/fan-2.gif";
break;
}
字段2 路径 /image/vvv.jsp这样不知道能不能满足你的要求。。
When '2' then 'fan-2.gif' end
From tb
Select Img Form tb where Id = "+id+";