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 RequiredFieldVa lidator
tb.Text = Convert.ToStrin g(e.Item.DataIt em("val"))
editCell.Contro ls.Add(tb)
If e.Item.DataItem ("req") Then
vld.ControlToVa lidate = FindControl(tb. ID.ToString)
vld.ErrorMessag e = "Required Field!"
editCell.Contro ls.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