We help IT Professionals succeed at work.
Get Started

How to validate asp textbox in side gridview

Last Modified: 2016-05-11
I am trying to validate asp textbox inside grid-view but my challenge is that i have 3 item templates in my aspx page,
The questions are generated dynamically after the grid view.bind() is called but i want to put some validation on the Answer field where users have to enter specific answer only based on the ID.  For example, If ID = 1 then they can only enter age number like 1 to 99. If ID = 2 then they can only enter some kind height values like 5.3, 5.8 etc. Here is how my current grid view look like
<asp:GridView ID="GV_Test" runat="server"  
                    ShowFooter="True" DataKeyNames="ID">

                        <asp:TemplateField  HeaderText="Question ID" Visible="true">
                                <asp:Label ID="lblQST_SK" runat="server" Text='<%# Eval("ID")%>'></asp:Label>

                        <asp:TemplateField ItemStyle-Width="150px" HeaderText="Questions">
                                <asp:Label ID="lblQuestions" runat="server" Text='<%# Eval("Question")%>'></asp:Label>

                        <asp:TemplateField HeaderText="Answer">                              
                                  <asp:TextBox ID="txtAn" runat="server" CssClass="form-control" Text='<%# Eval("Answer")%>' ></asp:TextBox>



Open in new window

I believe i have to use some kind of javascript that uses some kind event like onkeyup or onclick() something like this but not sure how to use it.   Please help.   thanks
Watch Question
Technical Analyst
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE