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.
-
Private Sub AddControls()
-
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
-
Dim cmd1 As SqlCommand = New SqlCommand("sp_get", con)
-
cmd1.CommandType = CommandType.StoredProcedure
-
Dim da1 As SqlDataAdapter = New SqlDataAdapter(cmd1)
-
Dim dt1 As DataTable = New DataTable
-
da1.Fill(dt1)
-
Dim dr1 As DataRow = dt1.NewRow
-
dt1.Rows.InsertAt(dr1, 0)
-
-
Dim txtqty As New TextBox
-
txtqty.ID = "txtqtyextra"
-
txtqty.Width = 20
-
-
Dim validation As New RequiredFieldValidator
-
validation.ID = "reqvaltxtqty"
-
validation.ControlToValidate = txtqty.ID
-
validation.ErrorMessage = "*"
-
-
Dim custvalidation As New CompareValidator
-
custvalidation.ID = "custvalidationtxtqty"
-
custvalidation.ControlToValidate = txtqty.ID
-
custvalidation.ErrorMessage = "Value should be greater than 0"
-
custvalidation.Type = ValidationDataType.Integer
-
custvalidation.Operator = ValidationCompareOperator.GreaterThan
-
custvalidation.ValueToCompare = 0
-
GridView1.Rows(GridView1.Rows.Count - 1).Cells(2).Controls.Add(txtqty)
-
End Sub
-