how to validate input of a detailsview?

Discussion in 'ASP .Net Web Controls' started by Cas, Oct 20, 2006.

  1. Cas

    Cas Guest

    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
     
    Cas, Oct 20, 2006
    #1
    1. Advertising

  2. 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.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
    >
    >
    >
    >
     
    Milosz Skalecki, Oct 20, 2006
    #2
    1. Advertising

  3. Cas

    André Guest

    Thanks

    "Milosz Skalecki" <> schreef in bericht
    news:...
    > 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.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
    >>
    >>
    >>
    >>
     
    André, Oct 20, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2plbGwgQXJuZQ==?=

    Input validation on detailsview

    =?Utf-8?B?S2plbGwgQXJuZQ==?=, Jun 1, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    12,080
    =?Utf-8?B?S2plbGwgQXJuZQ==?=
    Jun 26, 2006
  2. Cas
    Replies:
    2
    Views:
    703
    André
    Oct 20, 2006
  3. Cas

    how to validate input of a detailsview?

    Cas, Oct 20, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    809
    André
    Oct 20, 2006
  4. Feege
    Replies:
    0
    Views:
    490
    Feege
    Dec 20, 2005
  5. Alan Morris

    Detailsview control for data input

    Alan Morris, Oct 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    123
    Alan Morris
    Oct 8, 2006
Loading...

Share This Page