DataGrid.ItemDataBound原理

DataGrid.ItemDataBound原理当项被数据绑定到DataGrid控件后,将引发ItemDataBound事件。此事件为您提供了在客户端显示数据项之前访问该数据项的最后机会。当引发此事件后,该数据项将被设为空,并且不再可用。例如:执行步骤1privatevoidBindDoGrid(){stringstrSQL=”。。。。”;DataTabledt=clsCommon.clsDBExtend.Ex

大家好,欢迎来到IT知识分享网。DataGrid.ItemDataBound原理

当项被数据绑定到 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;”);
  }

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/27438.html

(0)

相关推荐

发表回复

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

关注微信