Raise validation in DataGrid-------CausesValidation in DataGrid
Source: Internet
Author: User
DataGrid CausesValidation in Datagrid
As we edit the DataGrid, we may want to validate the data entered by the user to ensure the correctness and completeness of the data. There are many different ways to solve this problem, such as: we can use the validation controls in Vs.net, such as: RequiredFieldValidator. So we need the Update button in the DataGrid to raise validation to verify that the data entered by the user is empty. The Update button contains a CausesValidation property.
Public Property CausesValidation () as Boolean
Members belong to: System.Web.UI.WebControls.LinkButton
Summary:
Gets or sets a value that indicates whether validation is performed when the System.Web.UI.WebControls.LinkButton control is clicked.
We can use this property to derive validation by controlling whether a WebControl is raised.
DataGrid ItemDataBound Event:
If (E.item.itemtype = listitemtype.edititem) Then
Setupdatecommandcausesvalidation (E.item, True)
End If
Private Function setupdatecommandcausesvalidation (ByVal item as DataGridItem, ByVal Valor as Boolean) as String
If (item. Hascontrols ()) Then
For each celula as control in item. Controls
For each Possiblebutton as control in Celula. Controls
If (Possiblebutton.gettype (). Name.equals ("Datagridlinkbutton")) Then
Dim LBT as LinkButton = CType (Possiblebutton, LinkButton)
If (LBT. Text.equals (Getupdatecolumntext ()) Then
Lbt. CausesValidation = Valor
Exit for
End If
End If
Next
Next
End If
End Function
Private Function Getupdatecolumntext () as String
Dim text as String = ""
For each coluna as DataGridColumn in Datagrid1.columns
If (Coluna. GetType (). Name.equals ("EditCommandColumn")) Then
Dim Colunaedit as EditCommandColumn = CType (Coluna, EditCommandColumn)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service