Connecting Tech Pros Worldwide Help | Site Map

dynamic validation does not work

  #1  
Old June 30th, 2009, 08:01 PM
parshupooja's Avatar
Familiar Sight
 
Join Date: Jun 2007
Posts: 159
hey all,

I have DataTable binded to Gridview . This Datatable contains Data from Database. Before binding it to Gridview I am adding extra line with few controls dynamically in it such as text box below. When page loads I see extra Text box on the bottom of gridview but Validation is not working. Any Idea?

I am calling this Function on each page load.

Expand|Select|Wrap|Line Numbers
  1. Private Sub AddControls()
  2. Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
  3.         Dim cmd1 As SqlCommand = New SqlCommand("sp_get", con)
  4.         cmd1.CommandType = CommandType.StoredProcedure
  5.         Dim da1 As SqlDataAdapter = New SqlDataAdapter(cmd1)
  6.         Dim dt1 As DataTable = New DataTable
  7.         da1.Fill(dt1)
  8.         Dim dr1 As DataRow = dt1.NewRow
  9.         dt1.Rows.InsertAt(dr1, 0)
  10.  
  11.        Dim txtqty As New TextBox
  12.         txtqty.ID = "txtqtyextra"
  13.         txtqty.Width = 20
  14.  
  15.         Dim validation As New RequiredFieldValidator
  16.         validation.ID = "reqvaltxtqty"
  17.         validation.ControlToValidate = txtqty.ID
  18.         validation.ErrorMessage = "*"
  19.  
  20.         Dim custvalidation As New CompareValidator
  21.         custvalidation.ID = "custvalidationtxtqty"
  22.         custvalidation.ControlToValidate = txtqty.ID
  23.         custvalidation.ErrorMessage = "Value should be greater than 0"
  24.         custvalidation.Type = ValidationDataType.Integer
  25.         custvalidation.Operator = ValidationCompareOperator.GreaterThan
  26.         custvalidation.ValueToCompare = 0
  27. GridView1.Rows(GridView1.Rows.Count - 1).Cells(2).Controls.Add(txtqty)
  28.  End Sub
  29.  
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net button does not work nicholas answers 4 November 19th, 2005 07:53 AM
Client validation not working with XML data islands in tables Dnna answers 2 November 18th, 2005 01:17 AM
Dynamic Validation Controls in Netscape Mike George answers 1 November 17th, 2005 05:53 PM
Macromedia's css dynamic repositioning does not work in Netscape Kor answers 6 July 23rd, 2005 11:59 AM