[英]How to access textbox value from a gridview ItemTemplate
Using C#, I am trying to access the value of a textbox defined within an ItemTemplate
inside a GridView
. 使用C#,我试图访问
GridView
内ItemTemplate
内定义的文本框的值。 That is, trying to get to an item such as: 即,尝试获取诸如以下内容:
<GridTemplateColumn UniqueName="Notes" HeaderText="Notes" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<TextBox ID="NotesInput" runat="server" Width="130px"></TextBox>
</ItemTemplate>
</GridTemplateColumn>
There are no events fired or no need to edit, just need to access it. 没有事件触发,也不需要编辑,只需要访问它即可。 The other columns are bound to database fields but this is a value that is entered, and needs to be processed.
其他列绑定到数据库字段,但这是一个输入的值,需要进行处理。 Can you please provide some guidance ?
您能提供一些指导吗?
您不能直接从代码中访问它,因为它必须位于网格视图中,然后必须选择一行然后找到所需的控件。
TextBox notesInput = (TextBox)gridName.Rows[rowIndex].FindControl("NotesInput");
你可以找到这样的文本框
var txt = (TextBox)YourGridName.Rows[e.RowIndex].FindControl("txtboxID");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.