Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

can't reference textbox inside details view

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bobby Edward - 06 Mar 2008 01:23 GMT
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
Teresita Núñez - SorCereSs - - 06 Mar 2008 01:46 GMT
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.

Signature

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

Bobby Edward - 06 Mar 2008 02:00 GMT
Thanks. I'll give that a try...

> Hi,
> just guessing, are you trying to write the current datetime at the textbox
[quoted text clipped - 4 lines]
> The error you're getting it's because it assumes that Now is a variable
> and tries to find it to take its value.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.