以下是在myDataGrid_ItemDataBound()事件中的增加javascript的代码。
private void myDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (itemType != ListItemType.Footer && itemType != ListItemType.Header && itemType != ListItemType.Separator)
{
DataGridItem item = (DataGridItem) e.Item;
item.Attributes.Add("onmouseover", "onGridMouseOver()");
item.Attributes.Add("onmouseout", "onGridMouseOut()");
if (item.ItemIndex % 2 == 0)
{
item.Attributes.Add("oldClassName", "gridOddRow");
}
else
{
item.Attributes.Add("oldClassName", "gridEvenRow");
}
DataView dataView = (DataView)myDataGrid.DataSource;
DataRowView row = dataView[item.DataSetIndex];
string orderID = row["ORDERID"].ToString();
string docid = ViewState["DOCID"].ToString();
TableCell intCell = ((TableCell)e.Item.Controls[1]);
string name = row["RNAME"].ToString();
intCell.Text = "<A href='#' οnclick='editOneData(\"" + name +"\",\""+orderID+"\")'" + " οnmοusemοve='window.status=\"修改名称\"'><img src='../../images/Word16.gif' alt='修改' border ='none'></A>";
intCell = ((TableCell)e.Item.Controls[2]);
intCell.Attributes.Add("onclick","javascript:if(DeleteConfirm()==false){return false;}");
}
}
以下是一段javascript DeleteConfirm()
function checkValue()
{
if (trim(document.all.txtName.value) == "")
{
alert("名称不可以为空!");
return false;
}
return true;
}
两段代码完成了服务器与客户端的交互。