Validating a value for a DataColumn

Posted by Richard Neil Ilagan on Stack Overflow See other posts from Stack Overflow or by Richard Neil Ilagan
Published on 2010-04-13T19:20:33Z Indexed on 2010/04/13 19:23 UTC
Read the original article Hit count: 224

Filed under:
|
|

Hello!

I'm using a DataGrid with edit functionalities in my project. It's handy, compared to having to edit its source data manually, but sadly, that means that I'll have to deal with validating user input a bit more.

And my problem is basically just that. When I set my DataGrid to EDIT mode, modify the values and then set it to UPDATE, what is the best way to check if a value that I've entered is, in fact, compatible with the corresponding column's data type?

i.e. (simple example)

// assuming
DataTable dt = new DataTable();
dt.Columns.Add("aa",typeof(System.Int32));

DataGrid dg = new DataGrid();
dg.DataSource = dt;
dg.DataBind();

dg.UpdateCommand += dg_Update;

// this is the update handler
protected void dg_Update(object src, DataGridCommandEventArgs e)
{
    string newValue = (someValueIEnteredInTextBox);

    // HOW DO I CHECK IF [newValue] IS COMPATIBLE WITH COLUMN "aa" ABOVE?

    dt.LoadDataRow(newValue, true);
}

Thanks guys. Any leads would be so much help.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET