首次顯示ASP.Net DetailsView數據時,您能告訴我如何填充此編碼中顯示的變量嗎?使用DetailsView文本框數據值填充變量
我已經嘗試過這個在代碼隱藏文件,但展示了一個錯誤:
Object reference not set to an instance of an object.
這是編碼:
Protected Sub DetailsViewDetails_DataBound(sender As Object, e As EventArgs) Handles DetailsViewDetails.DataBound
Dim txtOriginalRegistrationFee As TextBox
If DetailsViewDetails.CurrentMode = DetailsViewMode.Edit Then
txtOriginalRegistrationFee = FindControl("TextBoxRegistrationFee")
If String.IsNullOrEmpty(txtOriginalRegistrationFee.Text) = False Then
MsgBox(txtOriginalRegistrationFee)
End If
End If
End Sub
這是從aspx文件:
<asp:TemplateField HeaderText="RegistrationFee" SortExpression="RegistrationFee">
<EditItemTemplate>
<asp:TextBox ID="TextBoxRegistrationFee" runat="server" Text='<%# Eval("RegistrationFee") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBoxRegistrationFee" runat="server" Text='<%# Bind("RegistrationFee") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="LabelRegistrationFee" runat="server" Text='<%# Bind("RegistrationFee", "{0:c}") %>'></asp:Label>
</ItemTemplate>
<ItemStyle ForeColor="Blue" />
</asp:TemplateField>
*更新*
我嘗試使用這種基於你的幫助更新的編碼,但仍然得到「對象引用未設置爲對象的實例。」單擊DetailsView的編輯按鈕時出錯。
哪條線給出錯誤? – nickles80
如果String.IsNullOrEmpty(txtOriginalRegistrationFee.Text)= False然後 –
這是在一個gridview? – nickles80