Validating a value for a DataColumn

社会主义新天地 提交于 2019-12-25 01:45:54

问题


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.


回答1:


Can't you use a compare validator? it does check for the following datatypes

 String
 Double
 Date
 Currency
 Decimal

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.comparevalidator.aspx




回答2:


perhaps try some of these links:

http://msdn.microsoft.com/en-us/library/aa984376(VS.71).aspx
http://msdn.microsoft.com/en-us/library/0ye0dkkw.aspx
http://forums.silverlight.net/forums/p/134948/301233.aspx
http://www.daniweb.com/forums/thread101030.html#



来源:https://stackoverflow.com/questions/2632528/validating-a-value-for-a-datacolumn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!