如何替换图像而不是网格视图单元格中的值 [英] how to replace image instead of values in grid view cell

查看:82
本文介绍了如何替换图像而不是网格视图单元格中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我用绑定数据实现了垂直网格视图.在这里,我的要求是基于需要替换图像而不是值的值读取网格视图值.
在这里我可以读取值,但是如何传递图像而不是值.

例如,如果值为0,则需要放置一张图像;如果值为-ve,则需要放置另一张图像




受保护的void BindScoreData()
{
字符串DataId = Request.QueryString ["q"];
DataTable分数=新的DataTable();
SqlConnection conn =新的SqlConnection(connString);
conn.Open();
SqlCommand cmd =新的SqlCommand("PROC_DO_Score_Analysis",conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ DO_Ticker",SqlDbType.VarChar,50).Value = DataId;
//SqlDataReader reader = cmd.ExecuteReader();
SqlDataAdapter da =新的SqlDataAdapter(cmd);
da.Fill(得分);
Score.Columns [1] .ColumnName ="CompanyName";
Score.Columns [2] .ColumnName ="Sector";
Score.Columns [3] .ColumnName =子部门";
Score.Columns [4] .ColumnName ="FilingProbablility";
Score.Columns [5] .ColumnName ="settlementProbablility";
GridView1.DataSource =得分;
//gridScore.DataBind();
GridView1.DataSource = ConvertColumnsAsRows(Score);
GridView1.DataBind();
//GridView1.HeaderRow.Visible = false;
GridView1.HeaderRow.Visible = false;
foreach(gridScore.Rows中的GridViewRow行)
{
System.Web.UI.WebControls.Image img =(System.Web.UI.WebControls.Image)e.Row.FindControl("image1");
//字符串标头= gridScore.Columns [i] .HeaderText;
字符串h = row.Cells [0] .Text;
//字符串cellText = row.Cells [i] .Text;
字符串ss = row.Cells [1] .Text;
如果(ss =="0")
{
//img.ImageUrl ="resources/images/add.png";
//img.Visible = true;
}
否则,如果(ss =="-ve")
{
}
否则,如果(ss =="+ ve")
{
}
其他
{
}


}


如何传递该代码中上面突出显示的图像.

任何人都可以向我分享任何想法或相关代码.

Hi all,
I implemented vertical grid view with binding data.Here my requirement is read the grid view values based on that values i need to replace the images instead of values.
Here i can able to read the values but how can i pass images instead of values.

for example if the value is 0 i need to put one image,if the value is -ve i need to put the another image




protected void BindScoreData()
{
string DataId = Request.QueryString["q"];
DataTable Score = new DataTable();
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlCommand cmd = new SqlCommand("PROC_DO_Score_Analysis", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DO_Ticker", SqlDbType.VarChar, 50).Value = DataId;
//SqlDataReader reader = cmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(Score);
Score.Columns[1].ColumnName = "CompanyName";
Score.Columns[2].ColumnName = "Sector";
Score.Columns[3].ColumnName= "SubSector";
Score.Columns[4].ColumnName = "FilingProbablility";
Score.Columns[5].ColumnName = "settlementProbablility";
GridView1.DataSource = Score;
//gridScore.DataBind();
GridView1.DataSource = ConvertColumnsAsRows(Score);
GridView1.DataBind();
//GridView1.HeaderRow.Visible = false;
GridView1.HeaderRow.Visible = false;
foreach (GridViewRow row in gridScore.Rows)
{
System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.FindControl("image1");
//String header = gridScore.Columns[i].HeaderText;
string h = row.Cells[0].Text;
//String cellText = row.Cells[i].Text;
string ss = row.Cells[1].Text;
if (ss == "0")
{
//img.ImageUrl = "resources/images/add.png";
//img.Visible = true;
}
else if (ss == "-ve")
{
}
else if (ss == "+ve")
{
}
else
{
}


}


how can i pass images highlighted above in that code.

any one please share any idea or related code to me.

推荐答案

您是否正在使用类似的方法.
< asp:imagefield dataimageurlfield =< ImagePath>" headertext ="Image" xmlns:asp =#unknown">

在您的数据模型/实体类中,创建新的类型为string的包装器属性,这将使图像路径返回到所述字段. (在此属性的获取器中,记下突出显示的逻辑.

希望对您有帮助.
Are you using some thing like this.
<asp:imagefield dataimageurlfield="<ImagePath>" headertext="Image" xmlns:asp="#unknown">

In your data model/entity class create new wrapper property of type string which will return image path to said field. (in the getter of this property write down your highlighted logic.

Hope this will help you.


这篇关于如何替换图像而不是网格视图单元格中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆