Add an onclick event in the DataGrid for any Column

 
protected void ItemDB(object sender , System.Web.UI.WebControls.DataGridItemEventArgs e )
 
{
 
     DataView dv = (DataView)DataGrid1.DataSource;
 
     DataColumnCollection dc = dv.Table.Columns ;
 
     string strID;
 
     foreach (DataColumn dcCol in dv.Table.Columns)
 
     {
 
          if ((e.Item.ItemType == ListItemType.AlternatingItem )||(e.Item.ItemType == ListItemType.Item ))
 
          {
 
               strID = DataGrid1.DataKeys[e.Item.ItemIndex].ToString ();
 
               e.Item.Cells[dc.IndexOf(dc[dcCol.ColumnName])].Attributes.Add("style", "cursor:hand");
 
               e.Item.Cells[dc.IndexOf(dc[dcCol.ColumnName])].Attributes.Add("onclick", "javascript:window.open('details.aspx?id=" + strID + "'," + "'MyPage','height=300,width=300')");
 
          }
 
     }
 
}

你可能感兴趣的:(datagrid)