Validation for a datagrid column

S

steve.edison

I have been trying to validate a textbox value, but unfortunately, the
test for its validity is a function that must look up a value in a SQL
database. The function returns true or false and that will determine
the validity of the entry which is itself in a datagrid. Can anyone
provide a sample of how this code would look? Sadly, I am terribly new
to ASP.NET, so if you could also elaborate on whether any specific code
must be in the ASP or the code-behind, I would appreciate it.
 
G

Guest

I would suggest having a CustomValidator to do this. Add the custom validator
control to the .aspx page and in the .aspx.cs or .vb file, capture the
ServerValdiateEvent . In this event, write the code to connect to the
database and verify the value entered.
//Untested Pseudocode
public void ServerValidation(object sender, ServerValidateeventArgs args)
{
if(ValidateAgainstDB(txtVal.Text))
{
args.IsValid=false;
}

}
Here ValidateAgainstDB should verify the value against the database and
should return a true if the value is valid and false for Invalid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top