如何通过自定义验证器验证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) 
    { 

    } 
+2

空虚指的GridView可是没有任何行 –

+0

呀,这我的意思是 –

试试这个..

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) 
    { 
if(yourGridViewId.Rows.Count<1) 
args.IsValid=false; 
    }