471,082 Members | 719 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,082 software developers and data experts.

dynamic validation does not work

parshupooja
159 100+
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.  
Jun 30 '09 #1
0 1004

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by mr_burns | last post: by
1 post views Thread by Toby Miller | last post: by
1 post views Thread by Mike George | last post: by
1 post views Thread by Luis Ferrao | last post: by
3 posts views Thread by rgparkins | last post: by
reply views Thread by Steve Funk | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.