验证DataColumn的值 [英] Validating a value for a DataColumn

查看:121
本文介绍了验证DataColumn的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用带有编辑功能的DataGrid。相对于手动编辑源数据来说,这是比较方便的,但可悲的是,这意味着我必须处理更多的验证用户输入。



而我的问题基本上就是这样。当我将DataGrid设置为编辑模式时,请修改值,然后将其设置为UPDATE,检查我输入的值是否与其对应列的数据类型兼容,最好的方式是什么?



ie (简单示例)

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

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

dg.UpdateCommand + = dg_Update;

//这是更新处理程序
protected void dg_Update(object src,DataGridCommandEventArgs e)
{
string newValue =(someValueIEnteredInTextBox);

//如果[newValue]与COLOLNaa相匹配,该怎么办?

dt.LoadDataRow(newValue,true);
}

谢谢你们。任何潜在客户都会有这么大的帮助。

解决方案

也许尝试以下链接:



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#


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.

解决方案

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#

这篇关于验证DataColumn的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆