当项被数据绑定到 DataGrid 控件后,将引发 ItemDataBound 事件。此事件为您提供了在客户端显示数据项之前访问该数据项的最后机会。当引发此事件后,该数据项将被设为空,并且不再可用。
例如:
执行步骤1
private void BindDoGrid()
{
string strSQL = "。。。。";
DataTable dt = clsCommon.clsDBExtend.ExecuteDataTable(strSQL);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
执行步骤2
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex == -1)
return;
string strUserID = e.Item.Cells[7].Text;
string strFlowID = e.Item.Cells[4].Text;
string strFlowTypeID = e.Item.Cells[5].Text;
string strFlowTypeName = e.Item.Cells[6].Text;
string strUrl = "flag=0&strEml="+strFlowID+"&flowtypeid="+strFlowTypeID+"&flowtypename="+strFlowTypeName+"&userid="+strUserID;
e.Item.Cells[1].Text = "<a href=javascript:>" + GetLenString(e.Item.Cells[1].Text,25) + "</a>";
// e.Item.Cells[2].Text = "<font color=red>" + e.Item.Cells[2].Text + "</font>";
e.Item.Cells[3].Text = GetDateTime(e.Item.Cells[3].Text);
e.Item.Attributes.Add("onclick","openDocu('"+strUrl+"','"+strFlowTypeName+"')");
e.Item.Attributes.Add("style","cursor:hand;");
}