473,842 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default Values for DetailsView

esi
New to ASP.NET so any help you can offer would be great! I have been
searching the web all day to try and figure out how I can add a
default value to a field on a DetailsView control.

I did find a few examples on the web and I understand what the code is
trying to do, but I cannot get it to work for me.

Here is my code:

<asp:DetailsVie w ID="DetailsView 1" runat="server" AllowPaging="Tr ue"
AutoGenerateRow s="False"
BackColor="Whit e" BorderColor="#E 7E7FF" BorderStyle="No ne"
BorderWidth="1p x"
CellPadding="3" DataKeyNames="D efectID"
DataSourceID="S qlDataSource2" Font-Names="Arial"
Font-Size="8pt" GridLines="Hori zontal" Height="50px"
Width="331px" OnPreRender="De tailsView1_PreR ender">
<FooterStyle BackColor="#B5C 7DE" ForeColor="#4A3 C8C" />
<RowStyle BackColor="#E7E 7FF" ForeColor="#4A3 C8C" />
<PagerStyle BackColor="#E7E 7FF" ForeColor="#4A3 C8C"
HorizontalAlign ="Right" />
<Fields>
<asp:BoundFie ld DataField="Defe ctID"
HeaderText="Def ectID" InsertVisible=" False"
ReadOnly="True" SortExpression= "DefectID" />
<asp:BoundFie ld DataField="Insp ID" HeaderText="Ins pID"
SortExpression= "InspID" />
<asp:BoundFie ld DataField="Defe ctCode"
HeaderText="Def ectCode" SortExpression= "DefectCode " />
<asp:BoundFie ld DataField="TBL" HeaderText="TBL "
SortExpression= "TBL" />
<asp:BoundFie ld DataField="Sche maticRef"
HeaderText="Sch ematicRef" SortExpression= "SchematicR ef" />
<asp:BoundFie ld DataField="Defe ctQty"
HeaderText="Def ectQty" SortExpression= "DefectQty" />
<asp:BoundFie ld DataField="Test Symptom"
HeaderText="Tes tSymptom" SortExpression= "TestSympto m" />
<asp:BoundFie ld DataField="Symp tomNumber"
HeaderText="Sym ptomNumber" SortExpression= "SymptomNum ber" />
<asp:BoundFie ld DataField="Tech " HeaderText="Tec h"
SortExpression= "Tech" />
<asp:BoundFie ld DataField="Seri alNum"
HeaderText="Ser ialNum" SortExpression= "SerialNum" />
<asp:BoundFie ld DataField="Repa irBy"
HeaderText="Rep airBy" SortExpression= "RepairBy" />
<asp:BoundFie ld DataField="Rete stedBy"
HeaderText="Ret estedBy" SortExpression= "RetestedBy " />
<asp:BoundFie ld DataField="Rete stDate"
HeaderText="Ret estDate" SortExpression= "RetestDate " />
<asp:BoundFie ld DataField="Pass Fail"
HeaderText="Pas sFail" SortExpression= "PassFail" />
<asp:BoundFie ld DataField="Repa irComments"
HeaderText="Rep airComments" SortExpression= "RepairComments " />
<asp:CommandFie ld ShowEditButton= "True"
ShowInsertButto n="True" />
</Fields>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -

Protected Sub DetailsView1_Pr eRender(ByVal sender As Object, ByVal
e As System.EventArg s)
If DetailsView1.Cu rrentMode = DetailsViewMode .Insert Then
Dim ThisControl As TextBox
ThisControl = DetailsView1.Fi ndControl("Pass Fail")
ThisControl.Tex t = "Pass"
End If
End Sub

*Note - I have tried the code on the following events: PreRender,
DataBinding, and ItemInserting, ensuring that the asp: code is updated
correctly.

Without the default being set for the PassFail field the update works
well.

This is the error message I'm receiving (Line 83):

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object reference not
set to an instance of an object.

Source Error:
Line 81: Dim ThisControl As TextBox
Line 82: ThisControl =
DetailsView1.Fi ndControl("Pass Fail")
Line 83: ThisControl.Tex t = "Pass"
Line 84: End If
Line 85: End Sub

Basically what I am trying to do is be able to insert new detail
records. I get the error when I click the "Insert" link at the bottom
of the DetailsView control.

I am using Visual Web Developer 2005 Express Edition, but I do have a
full version of .NET Studio (2005).

Any tips or hints would be appreciated! Thanks in advance!

Jun 27 '08 #1
0 1119

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4442
by: sck10 | last post by:
Hello, I am trying to change a value when a user goes into edit mode on a DetailsView control. I am trying to use the following, but can not figure out how to get to the bound field ("MyBoundField") to set its new value. Any help with this would be appreciated. Sub EmployeeDetailView_ModeChanged(ByVal sender As Object, ByVal e As EventArgs) Select Case CustomerDetailView.CurrentMode
0
1494
by: rlueneberg | last post by:
I am having difficulty with preserving field values in a DetailsView control after clicking the insert button event. protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { e.KeepInInsertMode = true; GridView1.DataBind(); } What I noticed is if I click in a button outside DetailsView it does
0
1107
by: cjbland | last post by:
First off I apologize if this has been discussed before, I'm not certain how to search for what I'm looking for so I figured I'd throw this out there and see what I got. I am working with a DetailsView (Insert mode) in ASP.NET 2.0 and one of the fields I give a default value. <asp:DetailsView ....> <asp:TemplateField HeaderText="Date Entered" SortExpression="d_entered">
0
1250
by: Seok Bee | last post by:
Dear Experts, In my web application, I have a Master/Detail display of records using Gridview and DetailsView controls. Whenever, I made a selection of a record from the Gridview control, the detail information of the record will be displayed in the DetailsView control. Information in the editable in the detailsview by allowing user to have the edit option. On top of that I also allow user to add new record through the detailsview...
3
3425
by: clickon | last post by:
I have a DetailsView control and when it get's updated i send an email containing the new details. I have used the ItemUpdating event handler for the DetailsView and i am populating the MailMessage.Body property with a string variable which i build up using something like String strMessageBody = "Field1 = " + e.NewValues.ToString() + "\nField2 = " + e.NewValues.ToString(); This works fine apart from when one of the fields i am...
4
15024
by: Mark Olbert | last post by:
I am struggling with trying to retrieve the value of an autoincrement identity field after a DetailsView Insert operation. The DetailsView is bound to an SqlDataSource control. So far as I can tell, nowhere in the arguments for either the Inserted event for the DetailsView or the Inserted event for the SqlDataSource control is the value stored. Adding a dummy bound column for the identity field to the DetailsView doesn't work, either. ...
0
1864
by: miketayloruk | last post by:
I'm using a detailsview control that I want to use to insert data to a table. One of the fields is a date field and I want that to default to todays date. In classic asp I would do it like this: <input name="textfield" type="text" value="<%=now()%>" /> How do I do this in ASP.NET, heere is my current code: <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="data_key"
1
1684
by: andy4k | last post by:
i am trying to populate a detailsview insert view date field with todays date and converted 1 to template view and herd ya can do it through data binding in the code be hind and i be damned if i can find the heading and footer ya put in the code behind for a detailsview data binder if ya double click on the details view it creates the 1 for changes but god knows how ya suppost to find the 1 for databinding if thats the 1 a need any1 know where...
0
1496
by: Nirmal Singh | last post by:
How can I (programattically) set a Detailview control into Insert mode and set data to default values? Nirmal
0
9872
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10612
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10314
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7858
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7038
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.