我有一个在 tr/td 中有几个文本框的 formview。我正在尝试使用 .FindControl 方法获取文本框,但它返回 null。FormView 始终处于编辑模式(因此我始终处于 EditItemTemplate 中),并且我正在尝试将查询字符串值加载到来自上一页的文本框中,因此我确实需要在 page_load 上发生这种情况。我一直在 Gridviews 上这样做:
txtFirstName = (TextBox)fvGeneralInfo.FindControl("txtFirstName");
或像这样:
txtFirstName = (TextBox)fvGeneralInfo.FooterRow.FindControl("txtFirstName");
或像这样:
txtFirstName = (TextBox)fvGeneralInfo.Rows.FindControl("txtFirstName");
是什么赋予了?
<asp:FormView ID="fvGeneralInfo" runat="server"
DataSourceID="objInstructorDetails"
OnItemCommand="fvGeneralInfo_ItemCommand"
OnItemUpdated="fvGeneralInfo_ItemUpdated"
DefaultMode="Edit"
DataKeyNames="InstructorID" >
<EditItemTemplate>
<table>
<tr>
<td colspan="2" class="Admin-SubHeading" style="padding-left:10px;">General Info:</td>
</tr>
<tr>
<td class="Admin-FieldLabel">ID:</td>
<td><asp:TextBox ID="txtInstructorId" runat="server" CssClass="Admin-Textbox" ReadOnly="true" Text='<%# Bind("InstructorID") %>' /></td>
</tr>
<tr>
<td class="Admin-FieldLabel">First Name:</td>
<td><asp:Textbox ID="txtFirstName" runat="server" CssClass="Admin-Textbox" Text='<%# Bind("FirstName") %>' /></td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>