事件示例 privatevoid DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem) { e.Item.Attributes.Add("onclick","__doPostBack('"+((LinkButton)e.Item.Cells[4].Controls[0]).ClientID.Replace("__","$_")+"','')"); this.Label1.Text+="***"+"__doPostBack('"+((LinkButton)e.Item.Cells[4].Controls[0]).ClientID.Replace("__","$_")+"','')"; } if(e.Item.ItemType==ListItemType.EditItem) { e.Item.Attributes.Add("ondblclick","__doPostBack('"+((LinkButton)e.Item.Cells[5].Controls[0]).ClientID.Replace("__","$_")+"','')"); for(int i=1;i<4;i++) ((TextBox)e.Item.Cells[i].Controls[0]).Attributes.Add("onmouseover","this.select()"); } }void Item_Bound(Object sender, DataGridItemEventArgs e) { // Use the ItemDataBound event to customize the DataGrid control. // The ItemDataBound event allows you to access the data before // the item is displayed in the control. In this example, the // ItemDataBound event is used to format the items in the // CurrencyColumn in currency format. if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)) { // Retrieve the text of the CurrencyColumn from the DataGridItem // and convert the value to a Double. Double Price = Convert.ToDouble(e.Item.Cells[2].Text); // Format the value as currency and redisplay it in the DataGrid. e.Item.Cells[2].Text = Price.ToString("c"); } }