itemdatabound小结
来源:互联网 发布:禾川plc解密软件 编辑:程序博客网 时间:2024/05/16 05:13
在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事件来修改或者读取数据
比如,要显示某人的存款金额已经少于某个数额了,要用红色来显示等。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事件来修改或者读取数据
- itemdatabound小结
- itemdatabound小结
- ItemDataBound
- Repeater ItemDataBound
- 使用 ItemDataBound 、 ItemCreated 事件
- ItemCreated && ItemDataBound && ItemCommand
- DataGrid的ItemDataBound事件
- DataGrid的ItemDataBound事件
- DataGrid的ItemDataBound事件
- ItemDataBound的用法
- DataList.ItemDataBound 事件
- DataGrid.ItemDataBound原理
- repeat循环绑定ItemDataBound
- Repeater.ItemDataBound事件
- repeat循环绑定ItemDataBound .
- DataGrid的ItemDataBound用法实例
- ItemDataBound,ItemCreated的发生时间
- Repeater控件的ItemDataBound事件
- 一直很安静
- .NET开发人员基本概念题
- 检查字符串的长度
- SWT 和 JFace,第 1 部分: 如何创建简单的 SWT 应用程序
- 检查是否为数字
- itemdatabound小结
- SWT 和 JFace, 第 2 部分: 了解菜单、列表、组合框、表和树
- 当session过期后自动跳转到登陆页
- 看Kingofark's50 Points of View About Learning C++ And Programming有感
- SWT 和 JFace,第 3 部分: 了解 TabFolder、Canvas、StyledText 和其他多种控件
- 将ASP代码移植为VB COM组件(1)
- 批处理,解决启动web服务的简单方法
- Compare xpo with system objects
- SWT 和 JFace,第 4 部分: ToolBar、SashForm 以及其他控件和对话框