Solved

How Required Field validator  with details view or gridview in ASP.NET 2.0

Posted on 2007-12-04
5
6,218 Views
Last Modified: 2013-11-07
Can anyone tell me how I can use the required field validator control with a field that is in a gridview or details view control?
0
Comment
Question by:edi77
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 20408845
same as you would were it outside a gridview...

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtKeywords"
        ErrorMessage="YOu forgot to type something" Width="304px"></asp:RequiredFieldValidator>
0
 

Author Comment

by:edi77
ID: 20408933
ok thanks, so where inside here do i put that?

 <EmptyDataTemplate>
            <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
                DataKeyNames="LP" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px"
                Width="125px" OnItemInserted="DetailsView1_ItemInserted">
                <Fields>
                    <asp:BoundField DataField="DNA" HeaderText="DNA" SortExpression="DNA" />
                   
                   
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>
0
 
LVL 29

Expert Comment

by:QPR
ID: 20415491
Outside of the gridview tag, it doesn't make up part of the control. Just so long as it references the correct control then all is good.

</Fields>
</asp:DetailsView>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtKeywords"
        ErrorMessage="YOu forgot to type something" Width="304px"></asp:RequiredFieldValidator>

The control would be a textbox for example (not the details view) so make sure the control has an id value
0
 

Author Comment

by:edi77
ID: 20418142
where can i make sure it has an id value  ? WHen i created it i just used the details view template, when i go to click on the textbox in the properties window under fields it just says (collection)
so how do i access each field's id value to set the validator to the right field?
0
 
LVL 29

Accepted Solution

by:
QPR earned 500 total points
ID: 20422626
Are you using visual studio 2005? if so, select the details view in design mode and then click the smart tag and choose edit fields. Select the field in question and select convert this into a template. Close this dialogue box and then reopen it but this time choose edit templates. Your control label/textbox/whatever will now be shown as a single entity rather than the details view as a whole. Highlight the control and then give it an id in the properties window
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
2 questions 10 25
EF5: Question about Metadata Artifact Processing 4 15
imap read mail 1 27
Help with preventing downloading a zip file 10 35
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now