要让gridview上的某字段(列)上显示优、良、差:
①、当指定字段的值大于等于85时显示“优”②、当指定字段的值大于等于75而小于85时为“良”③、当指定字段的值小于75时为“差”
①、当指定字段的值大于等于85时显示“优”②、当指定字段的值大于等于75而小于85时为“良”③、当指定字段的值小于75时为“差”
解决方案 »
- 找不到类型或命名空间名称“CrystalReport1”(是否缺少 using 指令或程序集引用?)在线等急!!谢谢
- C#添加数据到excel
- winfrom怎么上传文件到服务器上呢?
- c# 创建win程序时,如何来模拟MessageBox
- 一个益智题,大家可以思考一下
- 新手求助 dataGridView 绑定 pictureBox问题
- 关于DataGrid显示问题.
- C# itextsharp 填充表单 Font 'STSongStd-Light' with 'UniGB-UCS2-H' is not recognized.
- 连接数据库失败为什么?
- 求.net 2002安装序列号!
- c#windows程序更新时是不是只要更新.exe文件就可以了?
- 生成dll的方式
<asp:TemplateField>
<ItemTemplate>
<%# Eval("数据").ToString().Equals("0") ? "男" : "女"%>
</ItemTemplate>
</asp:TemplateField>
在dataset中修改即可
例如
try
{
string str = "SELECT * FROM 表 where ...";
OracleDataAdapter da = new OracleDataAdapter(str, oracleconn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0]; }
catch (OracleException ee)
{
MessageBox.Show(ee.Message.ToString());
}
上边的程序将要查询的结果读到了dt中
foreach(DataRow dr in dt.Rows)
{
if(dr[/*列索引,你要判断的列的索引*/] >= 85)
{
dr[/*同一个索引*/] = "优";
}
else if(dr[/*列索引,你要判断的列的索引*/] >= 75 && dr[/*列索引,你要判断的列的索引*/] < 85)
{
dr[/*同一个索引*/] = "良";
}
else
{
dr[/*同一个索引*/] = "差";
}
}
上边的程序将数字换成了字符,
最后
this.datagridview1.DataSource = dt
若指定字段为非模板列:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int score = Convert.ToInt16(((Label)e.Row.Cells[列号]).Text);
if (score >= 85)
((Label)e.Row.Cells[列号]).Text = "优";
else if(score<85 & score>=75)
((Label)e.Row.Cells[列号]).Text = "良";
else
((Label)e.Row.Cells[列号]).Text = "差";
}
}若指定字段为模板列:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int score = Convert.ToInt16(((Label)e.Row.Cells[列号].FindControl("控件ID")).Text);
if (score >= 85)
((Label)e.Row.Cells[列号].FindControl("控件ID")).Text = "优";
else if(score<85 & score>=75)
((Label)e.Row.Cells[列号].FindControl("控件ID")).Text = "良";
else
((Label)e.Row.Cells[列号].FindControl("控件ID")).Text = "差";
}
}
姓名 语文
甲 95
乙 45
丙 86
丁 77
在gridview上得到以下结果:
总人数 优的人数 良的人数 差的人数4 2 1 1
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int score = Convert.ToInt16(((Label)e.Row.Cells[列号]).Text);
select (scroe)
case :"score>=85"
((label)e.row.cells[列号].text='优';
break;
case:"score>=75&score<85"
((label)e.row.cells[列号].text="良";
break;
case:"score<75"
((label)e.row.cells[列号].text="差";
break;
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int score = Convert.ToInt16(((Label)e.Row.Cells[列号]).Text);
select (scroe)
case :"score>=85"
((label)e.row.cells[列号].text="优";
break;
case:"score>=75&score<85"
((label)e.row.cells[列号].text="良";
break;
case:"score<75"
((label)e.row.cells[列号].text="差";
break;
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int score = Convert.ToInt16(((Label)e.Row.Cells[列号]).Text);
switch (scroe)
case :"score>=85"
((label)e.row.cells[列号].text="优";
break;
case:"score>=75&score<85"
((label)e.row.cells[列号].text="良";
break;
case:"score<75"
((label)e.row.cells[列号].text="差";
break;
}
}
<%# int.Parse(Eval("").ToString())>=85?"优":int.Parse(Eval("").ToString())>=75?"良":"差"%>
姓名 语文
甲 95
乙 45
丙 86
丁 77
在gridview上得到以下结果:
总人数 优的人数 良的人数 差的人数 4 2 1 1
姓名 语文
甲 95
乙 45
丙 86
丁 77
在gridview上得到以下结果:
总人数 优的人数 良的人数 差的人数 4 2 1 1
姓名 语文
甲 95
乙 45
丙 86
丁 77
在gridview上得到以下结果:
总人数 优的人数 良的人数 差的人数 4 2 1 1