Default Values for DetailsView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • esi

    Default Values for DetailsView

    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!

Working...