我在我的项目中使用了一个具有编辑功能的DataGrid。与手动编辑其源数据相比,它很方便,但遗憾的是,这意味着我必须更多地处理验证用户输入的问题。
我的问题基本上就是这样。当我将DataGrid设置为编辑模式,修改值,然后将其设置为UPDATE时,检查我输入的值是否与相应列的数据类型兼容的最佳方法是什么?
即(简单示例)
// 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);
}谢谢你们。任何线索都能帮上大忙。
发布于 2010-04-14 03:27:22
不能使用比较验证器吗?它会检查以下数据类型
String
Double
Date
Currency
Decimalhttp://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.comparevalidator.aspx
发布于 2010-04-14 04:20:31
也许可以试试下面的一些链接:
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
复制相似问题