且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在gridview中查找文本框控件

更新时间:2021-08-01 08:24:01

只需尝试下面的代码

just try the code below
string s = datagridview1.CurrentCell.EdittedFormattedValue.ToString();



这将为您提供当前单元格值。


This will give you current cell value.


为了得到嵌入在gridview中的textbox的值,你需要找到文本框所在的行索引,你需要知道触发事件的命令arguement和rowcommand_event。



我们使用以下代码派生行索引:



In order to get the value of textbox which is embedded within a gridview, You need to find row index in which the textbox is present and you need to know the command arguement which fires the event and the rowcommand_event.

We derive the row index using the following code:

int rowIndex = ((GridViewRow((LinkButton)e.CommandSource).NamingContainer).
RowIndex;





获取行索引后,我们需要知道文本框的id,我们想让它们的文本我们假设我们的文本框有一个idtxtTitle,我们得到它包含的文本如下:





After getting the row index we need to know the id of the textbox whose text we want to get let us assume that our textbox has an id "txtTitle" and we derive the text it contains as follows:

string title = ((TextBox)GridView1.Rows[rowIndex].FindControl("txtTitle")).Text;


TextBox txt=(TextBox)GridViewFRM.Rows[i].Cells[0].FindControl("GVQuestionTextBox");
string Ques = txt.Text;



http://www.aspsnippets.com/ Green / Articles / Find-and-access-Text-control-in-GridView-FooterTemplate-Footer-Row-in-ASPNet.aspx [ ^ ]

http ://www.aspdotnet-suresh.com/2012/06/get-find-controls-inside-of-aspnet.html [ ^ ]



-KR


http://www.aspsnippets.com/Green/Articles/Find-and-access-Value-of-TextBox-control-in-GridView-FooterTemplate-Footer-Row-in-ASPNet.aspx[^]
http://www.aspdotnet-suresh.com/2012/06/get-find-controls-inside-of-aspnet.html[^]

-KR