简体   繁体   English

如何从 GridView 检索文本框值

[英]How to retrieve TextBox Value from GridView

I have a gridview and created dynamic TextBox in the RowDataBound event as我有一个gridview并在RowDataBound事件中创建了动态TextBox作为

TextBox txtbox = new TextBox();
txtbox.ID = "txt1";
txtControl.Text = "SoomeValue";

When I'm trying to retrieve the value on a button click as当我尝试检索button click上的值时, button click

    TextBox textboxValue = (TextBox)gv.Rows[rowIndex].Cells[cellIndex].FindControl("txt1");
    string value = textboxValue.Text;

It is always returning null beside it is having the value它总是返回null除了它具有value

Answer is No. You cannot retrieve dynamically added TextBox from GridView like you are trying.答案是否定的。您无法像尝试一样从 GridView 中检索动态添加的 TextBox。

If you use GridView, you need to add textbox inside Template Column at Design Time .如果您使用 GridView,则需要在设计时在模板列中添加文本框。

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

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