2013-04-18 99 views
1

如何通過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

呀,這我的意思是 –

回答

3

試試這個..

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