得到的GridView单元格文本框的值 [英] Get TextBox value from GridView cell

查看:176
本文介绍了得到的GridView单元格文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含模板字段的GridView。每个模板字段包含一个文本框。在GridView的最后一列包含SELECT命令字段。

在SELECT的点击,我想获得位于所选行的单元格文本框的值。

我试过:

 ((文本框)GridView1.Rows(e.Row.RowIndex).FindControl(TextBox1中))文本;

在Row_Updating事件,但它不工作。

我试过code在GridView控件的SelectedIndexChanged事件类似的变种,但它给错误:对象引用不设置到对象的实例


解决方案

您需要寻找一个细胞里面,里面没有一排,试试这个:

<$p$p><$c$c>((TextBox)GridView1.Rows[e.Row.RowIndex].Cells[iCellIndex].FindControl(\"TextBox1\")).Text;

您需要提供 iCellIndex - 具有文本的单元格的指数

哦,用方括号来表示集合项目。

I have a GridView containing template fields. Each template field contains a TextBox. Last column of the GridView contains SELECT command field.

On click of SELECT, I want to get the value of TextBox located in a cell of the selected row.

I tried:

((TextBox)GridView1.Rows(e.Row.RowIndex).FindControl("TextBox1")).Text;

in Row_Updating event but it is not working.

I tried a similar variant of code in SelectedIndexChanged event of GridView but it gives error: Object Reference not set to an instance of an object.

解决方案

You need to look inside of a Cell, not inside of a Row, try this:

((TextBox)GridView1.Rows[e.Row.RowIndex].Cells[iCellIndex].FindControl("TextBox1")).Text;

Where you need to supply iCellIndex - index of the cell that has the textbox.

Oh and use square brackets to indicate collection item.

这篇关于得到的GridView单元格文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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