can't reference textbox inside details view

B

Bobby Edward

What am I doing wrong?

When it gets to the "MyTextBox.Text = Now" line I get "Object reference not
set to an instance of an object."

PARTIAL HTML:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
CellPadding="4" DataKeyNames="ID" DataSourceID="adsObitDetails"
ForeColor="#333333"
GridLines="None" Height="50px" Width="100%">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
/>
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<Fields>
:
<asp:TemplateField HeaderText="Entered"
SortExpression="InputDateTime">
<EditItemTemplate>
<asp:TextBox ID="txtInputDateTime" runat="server"
Text='<%# Bind("InputDateTime") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtInputDateTime" runat="server"
Text='<%# Bind("InputDateTime") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("InputDateTime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
:
</Fields>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
/>
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:DetailsView>

CODE:
Protected Sub DetailsView1_ModeChanging(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DetailsViewModeEventArgs) Handles
DetailsView1.ModeChanging
If e.NewMode = DetailsViewMode.Insert Then
Dim MyTextBox As TextBox
MyTextBox =
CType(Me.DetailsView1.FindControl("txtInputDateTime"), TextBox)
MyTextBox.Text = Now
End If
End Sub
 
T

Teresita Núñez - SorCereSs -

Hi,
just guessing, are you trying to write the current datetime at the textbox
MyTextBox?
in that case, did you try...
MyTextBox.Tex = DateTime.Now.ToString()

The error you're getting it's because it assumes that Now is a variable and
tries to find it to take its value.

--

SorCereSs
MCTS: NET Framework 2.0 - Web-Based Client Development
MCPD: Web Developer
Microsoft Student Partner - Paraguay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top