验证DetailsView插入数据不为空,在对象数据源ObjectDataScource(ChannelDS)的Inserting事件中写如下代码:
protected void ChannelDS_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{
string name = "";
if(e.InputParameters[0]!=null)
name = e.InputParameters[0].ToString().Trim();
if (name == "")
{
//使用这种方法可以不破坏网页的结构
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Channel", "<script>alert('频道名不能为空!')</script>");
e.Cancel = true;
}
}
转载于:https://www.cnblogs.com/zitsing/archive/2008/03/18/zitsing.html