hi everyone
i have used few RFVs( RequiredFieldValidators) in my web form which ahs a datagrid as well. The top section of page allows adding of new records while data grid shows all added records with 'Edit-Cancel-Update' link buttons.
The problem is that I have used RFVs for the text boxes which r used for adding new record...but whenever even press Update link in the grid...it validated the textboxes as well...which is not required if grid'd links r pressed.
I know it may have to do with 'Form'...i.e. form submission...but can we somehow distinguish beween the two Submit actions.
thnx
yash.You would need to handle the ItemDataBound event of the grid. Found this in a search:
Public Sub Gridname_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.EditItem Then
SetUpdateCommandCausesValidation(e.Item, False)
End If
End Sub
Private Sub SetUpdateCommandCausesValidation(ByVal item As DataGridItem, ByVal fEnable As Boolean)
Dim ctrl As Control
Dim btn As Control
If item.HasControls Then
For Each ctrl In item.Controls
If ctrl.HasControls Then
For Each btn In ctrl.Controls
If btn.GetType.Name.Equals("DataGridLinkButton") Then
Dim lnkBtn As LinkButton = CType(btn, LinkButton)
If lnkBtn.Text.Equals(GetUpdateColumnText) Then
lnkBtn.CausesValidation = fEnable
End If
End If
Next
End If
Next
End If
End Sub
Private Function GetUpdateColumnText() As String
Dim col As DataGridColumn
Dim colEdit As EditCommandColumn
For Each col In KelompokPelayanan_grdPelayanan.Columns
If col.GetType.Name.Equals("EditCommandColumn") Then
colEdit = CType(col, EditCommandColumn)
Return colEdit.UpdateText
End If
Next
End Function
You need to use a customvalidator - or disable validation on the update link (which from the sounds of it, you do not desire to do because you need to validate something else).
i dont want to validate anything at all on click of linkbuttons...validation needs to be performed on click of Button control which is not a part of the grid, but is available in the form.
i tried using the code given by 'Mendhak'...but no success so far...actually i coudn't use it properly.
u said 'disable validation on the update link'...how is this done..?
Almost all WebControls has a property called "CauseValidation", if you set that to false then the validation will not be performed. By default it is set to true. I assume you are using Template Column if thats the case then simply set the CauseValidation property of those Update/Edit button to false. That should fix your problem.
Hope it helps.
DataGrid control doesn't have CausesValidation property..
i tried using the code given by 'Mendhak'...but no success so far...actually i coudn't use it properly.
Explain.
DataGrid control doesn't have CausesValidation property..
Not the DataGrid, you need to set the CauseValidation property of the Buttons you place within the DataGrid.
0 comments:
Post a Comment