473,383 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False"
BackColor="White" BorderColor="#E7E7FF" BorderStyle="None"
BorderWidth="1px"
CellPadding="3" DataKeyNames="DefectID"
DataSourceID="SqlDataSource2" Font-Names="Arial"
Font-Size="8pt" GridLines="Horizontal" Height="50px"
Width="331px" OnPreRender="DetailsView1_PreRender">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C"
HorizontalAlign="Right" />
<Fields>
<asp:BoundField DataField="DefectID"
HeaderText="DefectID" InsertVisible="False"
ReadOnly="True" SortExpression="DefectID" />
<asp:BoundField DataField="InspID" HeaderText="InspID"
SortExpression="InspID" />
<asp:BoundField DataField="DefectCode"
HeaderText="DefectCode" SortExpression="DefectCode" />
<asp:BoundField DataField="TBL" HeaderText="TBL"
SortExpression="TBL" />
<asp:BoundField DataField="SchematicRef"
HeaderText="SchematicRef" SortExpression="SchematicRef" />
<asp:BoundField DataField="DefectQty"
HeaderText="DefectQty" SortExpression="DefectQty" />
<asp:BoundField DataField="TestSymptom"
HeaderText="TestSymptom" SortExpression="TestSymptom" />
<asp:BoundField DataField="SymptomNumber"
HeaderText="SymptomNumber" SortExpression="SymptomNumber" />
<asp:BoundField DataField="Tech" HeaderText="Tech"
SortExpression="Tech" />
<asp:BoundField DataField="SerialNum"
HeaderText="SerialNum" SortExpression="SerialNum" />
<asp:BoundField DataField="RepairBy"
HeaderText="RepairBy" SortExpression="RepairBy" />
<asp:BoundField DataField="RetestedBy"
HeaderText="RetestedBy" SortExpression="RetestedBy" />
<asp:BoundField DataField="RetestDate"
HeaderText="RetestDate" SortExpression="RetestDate" />
<asp:BoundField DataField="PassFail"
HeaderText="PassFail" SortExpression="PassFail" />
<asp:BoundField DataField="RepairComments"
HeaderText="RepairComments" SortExpression="RepairComments" />
<asp:CommandField ShowEditButton="True"
ShowInsertButton="True" />
</Fields>

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

Protected Sub DetailsView1_PreRender(ByVal sender As Object, ByVal
e As System.EventArgs)
If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
Dim ThisControl As TextBox
ThisControl = DetailsView1.FindControl("PassFail")
ThisControl.Text = "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.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:
Line 81: Dim ThisControl As TextBox
Line 82: ThisControl =
DetailsView1.FindControl("PassFail")
Line 83: ThisControl.Text = "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 1067

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

Similar topics

1
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...
0
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,...
0
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...
0
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...
3
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...
4
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...
0
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: ...
1
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...
0
by: Nirmal Singh | last post by:
How can I (programattically) set a Detailview control into Insert mode and set data to default values? Nirmal
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.