Solved

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

Posted on 2007-12-04
5
6,240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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