简体   繁体   English

如何比较gridview列中的值

[英]How do I Compare values in column of a gridview

I am using asp.net 4 and c#. 我正在使用asp.net 4和c#。

I have a gridview with a textbox that needs a unique value for the database. 我有一个带文本框的gridview,该文本框需要数据库的唯一值。 This value is to sort the data by precendence with in the database. 此值用于按数据库中的优先级对数据进行排序。 All my other validators work but they only check the value in the one box. 我所有的其他验证器都可以工作,但是他们只检查一个框中的值。

How do I validate that the integers are unique in that column. 我如何验证整数在该列中是唯一的。

The only thing I found to do this is "DataKeyNames" but that does not stop it from allowing repeating numbers. 我发现要做的唯一一件事就是“ DataKeyNames”,但这并不能阻止它允许重复数字。

Updating the order is done on button click. 单击按钮即可完成更新订单。

Thanks for info. 感谢您提供信息。

我想您可以编写一个JavaScript方法,在提交之前先扫描onclientclick网格的内容。

You can use a customvalidator for validating this. 您可以使用customvalidator对此进行验证。 In the CustomValidator's OnServerValidate function you can repeat through all the rows of the grid view, get the textbox and its value and perform the unique check. 在CustomValidator的OnServerValidate函数中,您可以在网格视图的所有行中重复操作,获取文本框及其值并执行唯一检查。 For the Integer validation you can add a CompareValidator with Operator="DataTypeCheck" Type="Integer" 对于Integer验证,您可以添加带有Operator="DataTypeCheck" Type="Integer"的CompareValidator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM