how to validate input of a detailsview?

C

Cas

Hi,

I use a detailsview control for inputtng data. I want to check the user
input before it is sent to the database (min. /max value, not empty, only
some values allowed ...). When clicking on the insertbutton, i want a
warning if one or more inputs are not correct and the user must have the
opportunity to correct his errors (so all the fields must remains as it).

I know it exists e.g. "RequiredFieldValidator", but i can't link it to a
detailsview.

I tried this, but here i only can limit the length of an input.
The fields are "fld1', 'fld2' etc ...till 'fld5'

Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView1.ItemInserting
Dim fld,valuefld(5) As String
Dim i, tel As Integer
For i = 1 To 5
valuefld(i) = e.Values("fld" & i)
tel=len(value1(i))
if tel>255 then
valuefld(i)=left(valuefld(i),255)
end if
next
SqlDataSource1.InsertCommand =="insert into data (fld1,fld2,fld3,fld4,fld5)
values ('" & valuefld(1) ....
SqlDataSource1.ProviderName = "System.Data.OleDb"
End Sub


Thansk for help
Cas
 
M

Milosz Skalecki

Howdy,

DetailsView control is based on templates - controls within the template are
acessible after template is instantiated (after binding the data). Move
validation controls to the template:

<asp:DetailsView runat="server" ID="userDetails">
<Fields>
<asp:TemplateField>
<InsertItemTemplate>
<asp:TextBox runat="server" ID="userName"/>
<asp:RequiredFieldValidator runat="server" ID="userNameValidator"
ErrorMessage="Please enter the name" ControlToValidate="userName"/>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

hope this helps
 
A

André

Thanks

Milosz Skalecki said:
Howdy,

DetailsView control is based on templates - controls within the template
are
acessible after template is instantiated (after binding the data). Move
validation controls to the template:

<asp:DetailsView runat="server" ID="userDetails">
<Fields>
<asp:TemplateField>
<InsertItemTemplate>
<asp:TextBox runat="server" ID="userName"/>
<asp:RequiredFieldValidator runat="server" ID="userNameValidator"
ErrorMessage="Please enter the name" ControlToValidate="userName"/>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top