如何从DataGrid中的文本框中检索整数值 [英] how to retrieve integer values from a textbox in datagrid

查看:67
本文介绍了如何从DataGrid中的文本框中检索整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从datagrid的文本框中检索值.整数值只能作为字符串读取,因此无法进行价格计算,我们需要将输出作为整数.

I can''t retrieve value from textbox in datagrid. Integer values can be read only as string so price calculation cannot be done, we need the output as integer.

推荐答案

您需要获得一本C#书籍并阅读有关Type的内容转换.
You need to get a C# book and read about Type Conversion.


如果可以帮助您,切勿按单元格索引访问项目,请尽可能使用FindControl.永远不要使用Convert.ToInt,因为如果该值不是int,它将抛出异常,并且如何确定文本框中是否包含数字?使用int.TryParse,以便在用户未输入值或未输入文本值的情况下编写错误捕获代码.永远不要完全信任javascript验证程序,它们可能会遭到黑客攻击,并且如果人们试图找到一个弱链接来破坏您的网站,则会被黑客入侵.
Never access items by cell index if you can help it, use FindControl where-ever possible. NEVER use Convert.ToInt, as it will throw an exception if the value is not an int, and how can you be sure your textbox has a number in it ? Use int.TryParse so you can write error trapping code if your user did not enter a value, or entered a text value. Never trust javascript validators completely, they can be hacked, and will be if people try to find a weak link to break your site.


代码在
int i=Convert.ToInt(((TextBox)DataGrid1.Items[i].Cells[9].Controls[1])).Text.ToString());

这篇关于如何从DataGrid中的文本框中检索整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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