我想实现在GridView的一个模板列中放一个Image控件,
他能根据从数据库读取不同的值而显示不同的图片,
数据库相对应的值是"yes","no"。
------解决方案--------------------------------------------------------
在GridView_databound事件里面找到哪个img控件,然后根据每行显示img列的值来做个判断img的src取什么图片路径
- C# code
/// <summary> /// 控件绑定事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gdvStore_DataBound(object sender, EventArgs e) { for (int i = 0; i < this.gdvStore.Rows.Count; i++) { string strType = this.gdvStore.DataKeys[i]["storeType"].ToString().Trim(); DropDownList dl2 = new DropDownList(); dl2 = (DropDownList)gdvStore.Rows[i].Cells[7].FindControl("ddlStoreType"); if (strType == "-1")//判断店铺推荐排行:-1:不推荐 dl2.SelectedIndex = 0; if (strType == "0") //0:首页推荐 dl2.SelectedIndex = 1; if (strType == "1") //1:小说推荐 dl2.SelectedIndex = 2; } }
------解决方案--------------------------------------------------------
<%# Eval("")=="Yes"?"a.gif":"b.gif"%>
------解决方案--------------------------------------------------------
<img src='<%# Eval("字段").ToString()=="Yes"?"yes.gif":"no.gif"%>' />