itemdatabound小结

itemdatabound小结在DATAGRID中,如果要对某些记录进行格式化或者修饰,用到itemdatabound事件比较方便,比如,要显示某人的存款金额已经少于某个数额了,要用红色来显示等。itemdatabound事件发生在数据绑定到datagrid后,而其内容发送到客户端前。比如privatevoidOnItemDataBound(objectsender,       System.Web.UI.WebC

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用
在DATAGRID中,如果要对某些记录进行格式化或者修饰,用到itemdatabound事件比较方便,

比如,要显示某人的存款金额已经少于某个数额了,要用红色来显示等。itemdatabound事件发生在

数据绑定到datagrid后,而其内容发送到客户端前。比如

private void OnItemDataBound(object sender,

        System.Web.UI.WebControls.DataGridItemEventArgs e)

{

    // Check if the current row contains items; if it’s

    // a header or footer row that will throw an error

    if (e.Item.ItemType == ListItemType.Item ||

        e.Item.ItemType == ListItemType.AlternatingItem)

    {

        // Get a copy of the “dgLabel2” label that contains the

        // “Balance” value

        Label lblBalance = (Label)e.Item.FindControl(“dgLabel2”);

        // Convert the value contained in the label to a double type

        double dblBalance = Convert.ToDouble(lblBalance.Text);

        // If that numeric value is negative

        if(dblBalance < 0)

            // …display it in red

            e.Item.Cells[3].ForeColor = System.Drawing.Color.Red;

        // Get a copy of the “dgLabel1” label that contains the

        // “Country” value

        Label lblCountry = (Label)e.Item.FindControl(“dgLabel1”);

        // …convert it to a string

        string strCountry = lblCountry.Text;

        // If it’s a North American country…

        if(strCountry == “USA” ||

            strCountry == “Mexico” ||

            strCountry == “Canada”)

        {

            // Get a copy of the “dgLabel0” label that contains the

            // “CustomerID” value, we’ll use it in the query string

            // for the popup

            Label lblID = (Label)e.Item.FindControl(“dgLabel0”);

            // …convert it to a string

            string strID = lblID.Text;

            // Replace the “Country” value displayed in the datagrid

            // with “Jamaica”, placed in a hyperlink who’s OnClick

            // event calls a javascript “popup” window

            e.Item.Cells[2].Text = “<a href=/”popup.aspx?id=” + strID +

                “/” onClick=/”popup(this.href); return false;/”>Jamaica</a>”;

        }

    }

}

而itemcreated事件和它有些不同,itemcreated发生在itemdatabound事件前,当datagrid中的每一项创建了但没

有数据时,所以不能用itemcreated事件来修改或者读取数据

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182361.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java学习之Spring MVC路由映射

    Java学习之SpringMVC路由映射0x00前言补充缺失的Javaweb部分内容。0x01SpringMVC路由映射web.xml中配置解析路径<display-name&

    2021年12月13日
    88
  • python allure报告_Pytest+Allure 定制报告

    python allure报告_Pytest+Allure 定制报告前言:最近在研究接口自动化的框架,好的测试报告在整个测试框架起到至关重要的部分。终于被我发现一个超好用的报告框架,不仅报告美观,而且方便CI集成。就是它,就是它:AllureTestReport!!!先上一张报告效果图:python版本及必要库python3.5pytest3.3.3pytest-allure-adaptor1.7.9一、环境配置安装Python依赖库:pip3…

    2022年7月26日
    21
  • qt将毫秒级时间戳转换为日期(js把对象变成字符串)

    需要加入的头文件:#include<QTime>一.秒单位时间转为字符串时、分、秒格式输出inttime_sec=100;QStringtimer=QTime(0,0,0).addSecs(int(time_sec)).toString(QString::fromLatin1(“HH:mm:ss”));qDebug()<<timer;//输出:”00:01:40″二.秒单位时间转为字符串时、分、秒、毫秒格式输出..

    2022年4月12日
    577
  • 图的数据结构_数据结构关于图的算法

    图的数据结构_数据结构关于图的算法图的定义和术语完全图:任意两个点都有一条边相连连通图(强连通图)连通分量(强连通分量)有向图和无向图的工程案例#include “pch.h”#include <iostream>using namespace std;//有向图 无向图 有向网 无向网enum GraphKing { DG, DN, UDG, UDN };//定义图…

    2022年8月18日
    4
  • 国密算法概述_国密算法一定要通过硬件吗

    国密算法概述_国密算法一定要通过硬件吗国密即国家密码局认定的国产密码算法,即商用密码。国密算法是国家密码局制定标准的一系列算法。其中包括了对称加密算法,椭圆曲线非对称加密算法,杂凑算法。具体包括SM1,SM2,SM3等,其中:SM2为国家密码管理局公布的公钥算法,其加密强度为256位。其它几个重要的商用密码算法包括:SM1,对称加密算法,加密强度为128位,采用硬件实现;SM3,密码杂凑算法,杂凑值长度为32字节,和SM2算…

    2022年10月7日
    1
  • 什么是Load Average?

    什么是Load Average?运维工程师在日常运维中经常使用w、top、uptime等命令来查看系统当前运行的负载情况。那么作为运维工程师是如何通过以上命令来判断系统当前负载是否已经达到极限了呢?为此笔者总结了一下如何通过load

    2022年7月1日
    22

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号