473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to validate input of a detailsview?

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.DetailsViewInsertEventAr gs) 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

Oct 20 '06 #1
2 16191
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

--
Milosz Skalecki
MCP, MCAD
"Cas" wrote:
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.DetailsViewInsertEventAr gs) 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

Oct 20 '06 #2
Thanks

"Milosz Skalecki" <mi*****@REMOVEITwp.plschreef in bericht
news:F2**********************************@microsof t.com...
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

--
Milosz Skalecki
MCP, MCAD
"Cas" wrote:
>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.DetailsViewInsertEventA rgs) 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


Oct 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Afonin | last post by:
Hello: How can I validate the character encoding of the textbox in ASP.Net form? For instance, when the user fills out a form, I need to be sure that he is typing in English (I mean uses Latin...
1
by: mats | last post by:
Hell My problem is that I do not know how to validate input that I let the user type into my datagrid In one grid I let the user to type in a value into a template column - how do I make sure...
0
by: suresh | last post by:
How to validate input with datagrid control? i tried the following code from msdn...i have problem in adding handler to the columnchanging event..its not working for me? any bug in this code? is...
2
by: Basr | last post by:
I tried to use this script to validate the input of the form Ford. When I use the Input ype Button the script is OK I want to use a picture as a button but then the script does not function....
5
nathj
by: nathj | last post by:
Hi, I have been looking around the forum and the web for a way to achieve this and so far I have drawn a blank. So I head to the forum as I'm sure someone knows how to do this. I have a form...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
10
mariodavi
by: mariodavi | last post by:
Hi everybody, how to validate input text in the follow: if option combo = 1,2 e 3, input 1 and input 2 must be filled, if one of this values not selected in combo (to be others), filled input...
1
by: kasturi207 | last post by:
I want to validate input (text) which i have to check with databse record is exist. the code something like that:- <cfscript> function checkkp() { if (rscheck.recordcount NEQ 0) {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.