M
MattB
Hello. I'm creating a page to edit a person's record (name address, etc)
using a DataGrid. I want the fields that can be edited to be created at
runtime based on a list of columns in web.config. This is working fine,
and I can add a control (TextBox or DropDownList) dynamically for the
user to fill in a value. This works well for just adding controls for
data entry.
Now, I want to add validators on the fly as well and it not going quite
as smoothly. I'm suing the following excerpt in the ItemDataBound event
for this DataGrid:
Dim tb As New TextBox, vld As New RequiredFieldValidator
tb.Text = Convert.ToString(e.Item.DataItem("val"))
editCell.Controls.Add(tb)
If e.Item.DataItem("req") Then
vld.ControlToValidate = FindControl(tb.ID.ToString)
vld.ErrorMessage = "Required Field!"
editCell.Controls.Add(vld)
End If
IntelliSense is flagging the FindControl part saying:
"System.Web.UI.Control" cannot be converted to string
Is this a reasonabler approach that I just need to fix the syntax of, or
am I taking the wrong approach? Any suggestions? Thanks!
Matt
using a DataGrid. I want the fields that can be edited to be created at
runtime based on a list of columns in web.config. This is working fine,
and I can add a control (TextBox or DropDownList) dynamically for the
user to fill in a value. This works well for just adding controls for
data entry.
Now, I want to add validators on the fly as well and it not going quite
as smoothly. I'm suing the following excerpt in the ItemDataBound event
for this DataGrid:
Dim tb As New TextBox, vld As New RequiredFieldValidator
tb.Text = Convert.ToString(e.Item.DataItem("val"))
editCell.Controls.Add(tb)
If e.Item.DataItem("req") Then
vld.ControlToValidate = FindControl(tb.ID.ToString)
vld.ErrorMessage = "Required Field!"
editCell.Controls.Add(vld)
End If
IntelliSense is flagging the FindControl part saying:
"System.Web.UI.Control" cannot be converted to string
Is this a reasonabler approach that I just need to fix the syntax of, or
am I taking the wrong approach? Any suggestions? Thanks!
Matt