[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Validations in gridView

Posted on 2011-05-04
12
Medium Priority
?
337 Views
Last Modified: 2012-05-11
Hi,
  i am applying validations to GridView control.These validations are working fine but the problem is when ever validations raise in first row the remaining rows effected and shows the error messages.My intension is validation raise for perticuler row only.. Can any one help to overcome this problem. tanx in advance.
0
Comment
Question by:CPSRI
  • 5
  • 4
  • 3
12 Comments
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35687646
How do you validate your rows?  Do you validate them at the time when you bound your GridView?  If you are validating the rows at the time they are binded, you can inspect each row through the RowDataBound event of the GridView.  Inside the RowDataBound event, you can then get the row that a validation is raise and do something to it and ignore the other rows based on condition inside the event.
0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 35688153
do you have a validationgroup assigned?
0
 

Author Comment

by:CPSRI
ID: 35688171
This is my code.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="MemberID" AllowPaging="true"            
              ShowFooter="True" Width="99%" BorderStyle="None" GridLines="None" CssClass="myGrid"
        onrowdatabound="GridView1_RowDataBound" >
             
              <Columns>
             
 <asp:TemplateField>
     <ItemTemplate>
     <asp:Label ID="lblMemberID" Visible="false" Text='<%#Eval("MemberID")%>' runat="server"></asp:Label>
       
     </ItemTemplate>    
 </asp:TemplateField>

<asp:TemplateField HeaderText="Name">
            <ItemTemplate>
               <asp:Label ID="lblName" runat="server"><%#Eval("Name") %></asp:Label>        
            </ItemTemplate>
  </asp:TemplateField>


<asp:TemplateField HeaderText="Contact">
            <ItemTemplate>
                <asp:Label ID="lblContact" runat="server"><%#Eval("Contact")%></asp:Label>        
            </ItemTemplate>
 </asp:TemplateField>
   
    <asp:TemplateField HeaderText="Area">
            <ItemTemplate>
                 <asp:Label ID="lblAddress" runat="server"><%#Eval("Area")%></asp:Label>        
            </ItemTemplate>
        </asp:TemplateField>
   

             
   <asp:TemplateField HeaderText="Member">
            <ItemTemplate>
              <asp:Label ID="lblMember" runat="server"><%#Eval("Member")%></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
       
    <asp:TemplateField HeaderText="Sanctified">              
                            <ItemTemplate>
                            <asp:Label ID="lblSalvation" runat="server"><%#Eval("Sanctified")%></asp:Label>  
                            </ItemTemplate>                            
        </asp:TemplateField>    
       
        <asp:TemplateField ControlStyle-Width="70px" HeaderText="CallStatus">
    <ItemTemplate>
                 <asp:DropDownList ID="drdCallStatus" runat="server" AutoPostBack="false" OnSelectedIndexChanged="drdCallStatus_SelectedIndexChanged">
                 <asp:ListItem Value="None" Selected="True">NoUpdate</asp:ListItem>
                 <asp:ListItem>Appointment</asp:ListItem>
                 <asp:ListItem>Call</asp:ListItem>
                 </asp:DropDownList>
             </ItemTemplate>    
            </asp:TemplateField>
           
           <asp:TemplateField HeaderText="Comment">              
                            <ItemTemplate>                            
                                <asp:TextBox ID="txtComments" Text="" runat="server"></asp:TextBox>
                            </ItemTemplate>                            
              </asp:TemplateField>  
             
             
              <asp:TemplateField ControlStyle-Width="70px" HeaderText="Reminder">              
                            <ItemTemplate>                            
                                <asp:TextBox ID="txtReminder" Text="" runat="server"></asp:TextBox>
                                 </ItemTemplate>                            
              </asp:TemplateField>  
              <asp:TemplateField>              
                            <ItemTemplate>  
                                <asp:ImageButton ID="imgBtn" runat="server" ImageAlign="Middle" ImageUrl="~/Image/images/Calendar_scheduleHS.png" />
                                <asp:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="imgBtn" TargetControlID="txtReminder">
                                </asp:CalendarExtender>
                            </ItemTemplate>                            
              </asp:TemplateField>  
             
             
             
       
        <asp:TemplateField>              
                            <ItemTemplate>                            
                                <asp:Button ID="btnInsert" runat="server" Text="Update" OnClick="btnInsert_Click" />
                               
                            </ItemTemplate>                            
              </asp:TemplateField>
             
             
        <asp:TemplateField>
        <ItemTemplate>
        <asp:Label Text="" runat="server" ForeColor="Red" ID="lblSuccess"></asp:Label>
        <asp:RequiredFieldValidator ID="rfvNewVisitor" runat="server" ErrorMessage="select Status" InitialValue="None" ControlToValidate="drdCallStatus">
                            </asp:RequiredFieldValidator>
        </ItemTemplate>
       
        </asp:TemplateField>      
              </Columns>
              <FooterStyle BackColor="#CCCCCC" Height="25px" ForeColor="Black" />
       
</asp:GridView>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:dejaanbu
ID: 35688241
this is just a thought.... try giving validationgroup property to ur RequiredFieldValidator and give the same value to your button also.. just give it a try
0
 

Author Comment

by:CPSRI
ID: 35688572
Hi dejaanbu,
    I tried but it not working ,it raises the same error.
0
 

Author Comment

by:CPSRI
ID: 35688991
Hello please help to my question..
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35689791
OK.  It looks like your RequiredFieldValidator is triggered in all rows because your InitialValue which is "None" and the initial value in the dropdownlist is the same as Initial Value.  In the link below:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.initialvalue.aspx

It states, "Validation fails only if the value of the associated input control matches this InitialValue upon losing focus."  and since all of your dropdownlist per row have a value selected a "None", then upon losing focus, it will raise an error in all rows.

What you can do is try the following:

1.  Remove the default selected item "None" in your dropdownlist and replace it with empty string and then
2.  REMOVE InitialValue property in the validator

<asp:RequiredFieldValidator ID="rfvNewVisitor" runat="server" ErrorMessage="select Status"  ControlToValidate="drdCallStatus">
                            </asp:RequiredFieldValidator>

3.  Test it out.
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35689981
Correction on my previous post.  It will still have the same effect as before since the NoUpdate value is set to empty string.  if you put back value "None" and InitialValue is removed, the validator will never trigger since all listitems have values.

However, the problem really lies with the InitialValue property based on your code dump.
0
 

Author Comment

by:CPSRI
ID: 35690152
Hi Alfred1,
   when ever i removed the intial value from the RequiredFieldValidator and changed the value of dropdown value as None, The RequiredFieldValidator not validasting the condition.  if i apply the initialvalue to RequiredFieldValidator it still effecting as before.
0
 
LVL 21

Accepted Solution

by:
Alfred A. earned 2000 total points
ID: 35690287
OK.  One approach for this is to use the EditItem template to isolate all editing processes such as dropdown list selection and validation.  There is an example in the first link using a required field validator.  On the third link, check the "Adding Validation Controls to the Editing Interface".

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.edititemtemplate.aspx

http://www.codeproject.com/KB/webforms/EditGridviewCells.aspx

http://msdn.microsoft.com/en-us/library/ms972948.aspx
0
 

Author Closing Comment

by:CPSRI
ID: 35787817
Thank you .. Your given links are helped to understand more about that gridview validations.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

873 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