Solved

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

Posted on 2007-12-04
5
6,215 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Replacing HTML tags in Textarea/Textbox 5 31
C# Reverse int in fast ways 6 28
ConsoleSql 1 21
Events in static methods 3 31
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

13 Experts available now in Live!

Get 1:1 Help Now