【发布时间】:2017-05-15 03:59:49
【问题描述】:
gridview 中的按钮无法从隐藏的文本框中获取正确的值。
代码如下:
asp:
<columns>
<asp:TemplateField >
<ItemTemplate>
<asp:TextBox ID="txtFruit" runat="server" Visible="true" Text='<%# Bind("txtFruit")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="HiddentxtFruit" HeaderText ="Fruit" HeaderStyle-Width="0%" HtmlEncode="false" Visible="false" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Confirm">
<ItemTemplate>
<asp:Button ID="btnSubmit" Text="Confirm" runat="server" CommandName="Submit" />
</ItemTemplate>
</asp:TemplateField>
</columns>
后面的代码:
For intX As Integer = 0 To gridview1.Rows.Count - 1
Dim txtPLACE As TextBox = TryCast(gridview1.Rows(0).Cells(0).FindControl("txtFruit"), TextBox)
Next
或
For intX As Integer = 0 To gridview1.Rows.Count - 1
Dim txtPLACEss As TextBox = DirectCast(gridview1.Rows(intX).FindControl("txtFruit"), TextBox)
Next
这只会从 gridview 中获取第一行。
【问题讨论】:
-
你在使用 Row_updating 事件吗?
-
@RamSingh 不,我使用按钮单击