Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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