如何为放置在gridview中的文本框分配字符串值。 [英] how to assign a string value to textboxes placed in gridview.

查看:80
本文介绍了如何为放置在gridview中的文本框分配字符串值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

我正在开发一个Asp.net应用程序。这里我通过ADD ROW按钮单击事件动态创建gird视图行。所以现在我想在运行时为文本框分配一个字符串值。





但它显示错误 - :(

 索引  范围。必须为非负小于 集合。
参数名称: index







这里代码 - :

< pre lang =c#> str = sb.ToString();
string txtname =((TextBox)GridView1.Rows [i] .Cells [ 1 ] .FindControl( TextBox1))。文本;
txtname = sb.ToString()

;

解决方案

我们可以帮助你:我们没有在代码运行时访问代码,您甚至需要开始解决问题。所以自己解决它 - 这并不难。



在调试器中运行代码,并断开该代码片段的第一行。当执行到达断点时,您可以检查要执行的语句的各个部分,以找出错误的索引:i是否大于行数?至少有两个细胞吗?等等。

当您计算出哪个索引时,您可以开始回顾以前的代码,找出该索引错误的原因 - 但是您需要运行的代码来解决哪个问题。



去吧!这是一项非常值得开发的技能!


Dear sir,
I am developing an Asp.net application. Here I Create gird view rows dynamically by a ADD ROW button click event. So now I want to assign a string value to text boxes at the run time.


But it shows error-: (

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


)

Here the code -:

 str = sb.ToString();
 string txtname = ((TextBox)GridView1.Rows[i].Cells[1].FindControl("TextBox1")).Text;
txtname = sb.ToString()

;

解决方案

We can;t help you with that: we don't have access to your code when it's running, which you need to even begin to solve the problem. So fix it yourself - it's not hard.

Run your code in the debugger, and breakpoint the first line of that code fragment. When the execution gets to the breakpoint, you can examine the various parts of the statement to be executed to work out what index it wrong: is "i" greater than the number of rows? Are there at least two cells? and so on.
When you work out which index, you can start looking back at previous code to find out why that index s wrong - but you need the code running to work out which in the first place.

Go to it! This is a skill it is well worth developing!


这篇关于如何为放置在gridview中的文本框分配字符串值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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