如何通过自定义验证器验证gridview是否为空?
问题描述:
如何通过custom validator
验证GridView控件的空虚:如何通过自定义验证器验证gridview是否为空?
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="!!! "
ControlToValidate="GridView1" ValidationGroup="Add_valid" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
}
答
试试这个..
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if(yourGridViewId.Rows.Count<1)
args.IsValid=false;
}
空虚指的GridView可是没有任何行 –
呀,这我的意思是 –