网页上查询学生不及格信息状态显示为红色
//GridView设置显示数据
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
Font-Size="9pt" ForeColor="#333333">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="res_id" HeaderText="学生编号" />
<asp:BoundField DataField="stuname" HeaderText="学生姓名" />
<asp:BoundField DataField="stusex" HeaderText="学生性别" />
<asp:BoundField DataField="which_lesson" HeaderText="考试科目" />
<asp:BoundField DataField="taotiname" HeaderText="考试套题" />
<asp:BoundField DataField="res_total" HeaderText="考试成绩" />
<asp:BoundField DataField="res_subdate" HeaderText="考试时间" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
//加载绑定数据库数据
SqlConnection sqlcon;
string strCon = ConfigurationManager.AppSettings["conStr"];
protected void Page_Load(object sender, EventArgs e)
{
string sqlstr = "select * from tb_StuResult";//定义查询语句
sqlcon = new SqlConnection(strCon);//创建数据库连接
SqlDataAdapter myda = new SqlDataAdapter(sqlstr,sqlcon);//创建数据适配器
DataSet myds = new DataSet();//创建数据集
myda.Fill(myds,"tb_StuResult");//填充数据集
GridView1.DataSource = myds;//设置数据源
GridView1.DataBind();//绑定数据
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//遍历控件
{
DataRowView mydrv = myds.Tables["tb_StuResult"].DefaultView[i];
string score = Convert.ToString(mydrv["res_total"]);
if (Convert.ToInt32(score) < 60)//判断res_total值即学生成绩如果小于60分为不及格
{
GridView1.Rows[i].Cells[5].BackColor = System.Drawing.Color.Red;//成绩不及格时单无格显示红色
}
}
}
//GridView设置显示数据
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
Font-Size="9pt" ForeColor="#333333">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="res_id" HeaderText="学生编号" />
<asp:BoundField DataField="stuname" HeaderText="学生姓名" />
<asp:BoundField DataField="stusex" HeaderText="学生性别" />
<asp:BoundField DataField="which_lesson" HeaderText="考试科目" />
<asp:BoundField DataField="taotiname" HeaderText="考试套题" />
<asp:BoundField DataField="res_total" HeaderText="考试成绩" />
<asp:BoundField DataField="res_subdate" HeaderText="考试时间" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
//加载绑定数据库数据
SqlConnection sqlcon;
string strCon = ConfigurationManager.AppSettings["conStr"];
protected void Page_Load(object sender, EventArgs e)
{
string sqlstr = "select * from tb_StuResult";//定义查询语句
sqlcon = new SqlConnection(strCon);//创建数据库连接
SqlDataAdapter myda = new SqlDataAdapter(sqlstr,sqlcon);//创建数据适配器
DataSet myds = new DataSet();//创建数据集
myda.Fill(myds,"tb_StuResult");//填充数据集
GridView1.DataSource = myds;//设置数据源
GridView1.DataBind();//绑定数据
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)//遍历控件
{
DataRowView mydrv = myds.Tables["tb_StuResult"].DefaultView[i];
string score = Convert.ToString(mydrv["res_total"]);
if (Convert.ToInt32(score) < 60)//判断res_total值即学生成绩如果小于60分为不及格
{
GridView1.Rows[i].Cells[5].BackColor = System.Drawing.Color.Red;//成绩不及格时单无格显示红色
}
}
}
解决方案 »
- 学.net却不学asp.net就会找不到工作吗??
- 极难的问题:请教如何实现MAIL.BOKEE.COM的文件上传功能!
- DataGrid为何不能修改?请高手帮助!(附源码)
- 在asp.net中如何应用css样式表???(新手上战利路)
- 【求助】关于ASP.NET图像文件处理的问题。。。。。。。。。。
- 急!!!关于IEWebControls的使用
- 如何获得控件坐标
- 高分求:web窗体中的ListBox控件(服务器端)的item双击完成其他操作怎么实现?解决马上给分
- aspx页面上加这种代码是什么意思
- 我现在想连接ORACLE但是因为我是BS模式的。所以我的客户端不想要安装ORACLE
- EF包含外键表查询的问题,求助大神!!
- 点击【列印】需要等待3秒左右....怎么防止狂点 @@?
比如优先显示“通过”的课程,次之排列“补考”的,最后才是“重修”