Vraag : Formview - Uitzondering System.NullReference wanneer het gebruiken van findcontrol

Ik heb een vormmening met punt, tussenvoegselpunt en puntmalplaatjes uitgeven.  Ik heb een voorwerp datasource opnemend gebeurtenis gecodeerd om de parameters van formview te plaatsen.  Ik krijg de ongeldige verwijzingsuitzondering met de methode van de vondstcontrole van formview.  Ik heb nooit alle drie formviewmalplaatjes voordien gebruikt.  In het verleden, heb ik een formview met een standaardwijze van tussenvoegsel gebruikt om controles zonder een probleem te vinden.  Ik werkelijk begrijp niet waarom het niet de controle kan vinden.  Ik gebruik de controle Ajax toolket om een lijst terug te geven.  Hieronder zijn de het opnemen gebeurteniscode en de prijsverhoging voor de pagina.  Om het even welke suggesties zijn zeer appreciated.

public nietige SI_Inserting (objecten bron, ObjectDataSourceMethodEventArgs e)
{
//use formview instead

TextBox txtIncidentDatei = (TextBox) FormView1.FindControl („txtIncidentDatei“);
DropDownList ddlSecurityi = (DropDownList) FormView1.FindControl ( " ddlSecurityi“);
DropDownList ddlFacilityi = (DropDownList) FormView1.FindControl ( " ddlFacilityi“);
DropDownList ddlRatingi = (DropDownList) FormView1.FindControl ( " ddlRatingi“);
DropDownList ddlProgrami = (DropDownList) FormView1.FindControl ( " ddlProgrami“);
DropDownList ddlCategoryi = (DropDownList) FormView1.FindControl ( " ddlCategoryii“);
DropDownList ddlAreai = (DropDownList) FormView1.FindControl ( " ddlAreai " ); /> e.InputParameters

ecurityNumber“] = „xxxxxx“; /> e.InputParameters
tDate“] = txtIncidentDatei.Text.Trim (); /> e.InputParameters
yWhereOccurred“] = ddlFacilityi.SelectedItem.Text; /> e.InputParameters
WhereOccurred“] = ddlProgrami.SelectedValue; /> e.InputParameters
yLevel“] = ddlSecurityi.SelectedItem.Text; /> e.InputParameters
ing“] = ddlRating.SelectedValue; /> e.InputParameters
yOfIncident“] = ddlCategoryi.SelectedValue; /> e.InputParameters
ve“] = txtNarrative1.Text; /> e.InputParameters
tYear“] = txtYeari.Text; /> e.InputParameters
= „xxxxxx“;
}

aSource“ OnItemInserted= " FormView1_ItemInserted“ OnItemUpdated= " FormView_ItemUpdated " OnItemDeleted= " FormView_ItemDeleted " DataKeyNames= " RowNum "
>





Main

r>d>
<td>
DataSourceID= " SqlDataSource6“ DataTextField= " SecurityLevel“
DataValueField= " SecurityLevel“ SelectedValue='<%# bindt („SecurityLevel“) %>'>
d>>></tr>d>el ID= de " Label5Read“ runat= " server“ Text= " Programma waar Voorgekomen " >>>>>
DataSourceID= " SqlDataSource5“ DataTextField= " WardDescriptions“
DataValueField= " WardDescriptions“ SelectedValue='<%# bindt („ResidenceArea“) %>'>
d>
>
: Etiket ID= " Label1Read“ runat= Inherente Datum van " server“ Text= de ": „>
sp: Etiket ID= " Label3Read“ runat= Niveau van de Veiligheid van " server“ Text= het ": „>
Label ID= " Label2Read“ runat= " server“ Text= " Faciliteit waar Voorgekomen " >>
DataSourceID= " SqlDataSource1“ DataTextField= " FacilityDescriptions "
DataValueField= " FacilityDescriptions“ SelectedValue='<%# bindt („FacilityWhereOccured“) %>'>
d>
Label ID= " Label4Read“ runat= " server“ Text= " Classificatie van Recent Vooruitlopend Gedrag " >>
DataSourceID= " SqlDataSource7“ DataTextField= " RiskRating "
DataValueField= " RiskRating“ >

DataSourceID= " SqlDataSource2“ DataTextField= " ProgramDescription“
DataValueField= " ProgramDescription“ SelectedValue='<%# bindt („ProgramWhereOccurred“) %>'>
d>
Label ID= " Label6Read“ runat= Categorie van " server“ Text= de " van Incident: „>d>
DataSourceID= " SqlDataSource8“ DataTextField= " SeriousIncident“
DataValueField= " SeriousIncident“ SelectedValue='<%# bindt („CategoryOfIncident“) %>'>
d>
Label ID= " Label7Read“ runat= " server“ Text= Gebied " >
entTemplate>bPanel>
entTemplate><tr valign=top>d>tBox ID= " txtYearRead“ ReadOnly=true runat= " server“ Text='<%# bindt („IncidentYear“) %>'>r><td>xtBox ID= " txtNarrative1Read“ ReadOnly=true runat= " server“ TextMode=MultiLine Width=500px Height=195px MaxLength=1073741823 Text='<%# bindt („Verhaal“) %>'>r>
bel>
emplate>cc1: TabPanel>
abContainer>ton ID= " btnNew“ runat= " server“ Text= " Nieuwe“ CommandName= " Nieuwe“/>
ID= " btnDelete“ runat= " server“ Text= " schrapt“ CommandName= " schrapt“/>
Template><asp: Van het etiket ID= de " lblRowNum“ runat= " server“ Text='<%# bindt („RowNum“) %>' Visible=false>
ntainer ID= de " TabContainer1“ runat= " server“
Height= " 350px“ Width= " 700px“ ActiveTabIndex= " 0“ >


Main

r>d>tBox ID= " txtIncidentDate“ runat= " server“ Text='<%# bindt („IncidentDate“,“ {0: D} „) %>'>>age ID= de " Image10“ runat= " server“ ImageUrl= " Calendar_scheduleHS.png“/>
ntDate“ Enabled= " Ware " >
d>><td>
DataSourceID= " SqlDataSource6“ DataTextField= " SecurityLevel“
DataValueField= " SecurityLevel“ SelectedValue='<%# van " ddlSecurity“ van DropDownList ID= runat= " bindt („SecurityLevel“) %>'>
d>>></tr>d>el ID= de " Label5“ runat= " server“ Text= " Programma waar Voorgekomen " >>>>>
DataSourceID= " SqlDataSource5“ DataTextField= " WardDescriptions“
DataValueField= " WardDescriptions“ SelectedValue='<%# van " ddlArea“ van DropDownList ID= runat= " bindt („ResidenceArea“) %>'>
d>
>
: Etiket ID= " Label1“ runat= Inherente Datum van " server“ Text= de ": „>
Label ID= " Label3“ runat= Niveau van de Veiligheid van " server“ Text= het ": „>
Label ID= " Label2“ runat= " server“ Text= " Faciliteit waar Voorgekomen " >>
DataSourceID= " SqlDataSource1“ DataTextField= " FacilityDescriptions "
DataValueField= " FacilityDescriptions“ SelectedValue='<%# van " ddlFacility“ van DropDownList ID= runat= " bindt („FacilityWhereOccured“) %>'>
d>
Label ID= " Label4“ runat= " server“ Text= " Classificatie van Recent Vooruitlopend Gedrag " >>
e7“ DataTextField= " RiskRating "
DataValueField= " RiskRating“ >

DataSourceID= " SqlDataSource2“ DataTextField= " ProgramDescription“
DataValueField= " ProgramDescription“ SelectedValue='<%# bindt („ProgramWhereOccurred“) %>'>
d>
Label ID= " Label6“ runat= Categorie van " server“ Text= de " van Incident: „>d>
DataSourceID= " SqlDataSource8“ DataTextField= " SeriousIncident“
DataValueField= " SeriousIncident“ SelectedValue='<%# bindt („CategoryOfIncident“) %>'>
d>
Label ID= " Label7“ runat= " server“ Text= Gebied " >
entTemplate><tr valign=top>d>tBox ID= " txtYear“ runat= " server“ Text='<%# bindt („IncidentYear“) %>'>r><td>xtBox ID= de " txtNarrative1“ runat= " server“ TextMode=MultiLine Width=500px Height=195px MaxLength=1073741823 Text='<%# bindt („Verhaal“) %>'>r>
bel>
emplate>cc1: TabPanel>abContainer>ton ID= " btnUpdate“ runat= " server“ Text= " Update“ CommandName= " Update“/>
rtItemTemplate>TabContainer ID= " TabContainer1“ runat= " server“
Height= " 350px“ Width= " 700px“ ActiveTabIndex= " 0“ >


Main

r>d>tBox ID= " txtIncidentDatei“ runat= " server“ Text='<%# bindt („IncidentDate“,“ {0: D} „) %>'>ge ID= de " Image10i“ runat= " server“ ImageUrl= " Calendar_scheduleHS.png“/>
ntDatei“ Enabled= " Ware " >
d>><td>
DataSourceID= " SqlDataSource6“ DataTextField= " SecurityLevel“
DataValueField= " SecurityLevel“ SelectedValue='<%# van " ddlSecurityi“ van DropDownList ID= runat= " bindt („SecurityLevel“) %>'>
d>>></tr>d>el ID= de " Label5i“ runat= " server“ Text= " Programma waar Voorgekomen " >>>>>
DataSourceID= " SqlDataSource5“ DataTextField= " WardDescriptions“
DataValueField= " WardDescriptions“ SelectedValue='<%# van " ddlAreai“ van DropDownList ID= runat= " bindt („ResidenceArea“) %>'>
d>
>
: Etiket ID= " Label1i“ runat= Inherente Datum van " server“ Text= de ": „>
Label ID= " Label3i“ runat= Niveau van de Veiligheid van " server“ Text= het ": „>
Label ID= " Label2i“ runat= " server“ Text= " Faciliteit waar Voorgekomen " >>
DataSourceID= " SqlDataSource1“ DataTextField= " FacilityDescriptions "
DataValueField= " FacilityDescriptions“ SelectedValue='<%# van " ddlFacilityi“ van DropDownList ID= runat= " bindt („FacilityWhereOccured“) %>'>
d>
Label ID= " Label4i“ runat= " server“ Text= " Classificatie van Recent Vooruitlopend Gedrag " >>
e7“ DataTextField= " RiskRating "
DataValueField= " RiskRating“ >

DataSourceID= " SqlDataSource2“ DataTextField= " ProgramDescription“
DataValueField= " ProgramDescription“ SelectedValue='<%# van " ddlProgrami“ van DropDownList ID= runat= " bindt („ProgramWhereOccurred“) %>'>
d>
Label ID= " Label6i“ runat= Categorie van " server“ Text= de " van Incident: „>d>
DataSourceID= " SqlDataSource8“ DataTextField= " SeriousIncident“
DataValueField= " SeriousIncident“ SelectedValue='<%# van " ddlCategoryi“ van DropDownList ID= runat= " bindt („CategoryOfIncident“) %>'>
d>
Label ID= " Label7i“ runat= " server“ Text= Gebied " >
entTemplate>bPanel>
entTemplate><tr valign=top>d>tBox ID= " txtYeari“ runat= " server“ Text='<%# bindt („IncidentYear“) %>'>r><td>xtBox ID= de " txtNarrative1i“ runat= " server“ TextMode=MultiLine Width=500px Height=195px MaxLength=1073741823 Text='<%# bindt („Verhaal“) %>'>r>
bel>
emplate>cc1: TabPanel>
abContainer>ton ID= " btnInsert“ runat= " server“ Text= " Tussenvoegsel“ CommandName= " Tussenvoegsel“/>

Antwoord : Formview - Uitzondering System.NullReference wanneer het gebruiken van findcontrol

Hallo,

De controles zijn waarschijnlijk geen directe childcontrols aan formview. Probeer dit

 txtIncidentDatei van TextBox = FindControlRecursive (FormView1, „txtIncidentDatei“) als TextBox;

.
.
.
            openbare statische Controle FindControlRecursive (de wortel van de Controle, koordidentiteitskaart) {
                  als ((root.ID! = verklaar) && (identiteitskaart root.ID ==) nietig) keer wortel terug;

                  foreach (Controle CTRL in wortel. Controle) {
                        Gevonden controle = FindControlRecursive (CTRL, identiteitskaart);
                        als (gevonden! = ongeldige) gevonden terugkeer;
                  }

                  ongeldige terugkeer;
            }


/peter
Andere oplossingen  

 
programming4us programming4us