12 Replies - 1483 Views - Last Post: 17 August 2012 - 12:46 AM Rate Topic: -----

#1 Krimel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-August 12

I am trying to pull a value from a formview into a text box

Posted 15 August 2012 - 08:09 PM

I am afraid I am stuck on a problem that has me baffled. I am not a programmer so please bear with me on with my entry-level question.
My problem is I would like to pull a value from a formview into a text box outside of the form view. It seems like it would be simple enough, but I have struggled with this for days with an error that is engrained in my memory “system.nullreferenceexception: object reference not set to an instance of an object” I have researched this error with many results, but nothing I have tried solves my problem as I keep coming back to the same error.
I would greatly appreciate some advice on how to correct my code below.
<script runat="server">
    Public Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound


        Dim compliant As Label
       
        If FormView1.CurrentMode = FormViewMode.[ReadOnly] Then
            compliant = TryCast(FormView1.FindControl("label1"), Label)
            If Not compliant Is Nothing Then
                compliant.Text = "Nothing Returned"
            End If
            If compliant.Text = "Yes" Then
                TextBox2.Text = " Yes you passed"
            ElseIf compliant.Text = "No" Then
                TextBox2.Text = " No you did not pass"
            End If
        
            TextBox2.Text = compliant.Text
        End If
    End Sub
        
    </script>

This post has been edited by AdamSpeight2008: 15 August 2012 - 08:15 PM
Reason for edit:: USE THE CORRECT CODE TAG PLEASE


Is This A Good Question/Topic? 0
  • +

Replies To: I am trying to pull a value from a formview into a text box

#2 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 12:28 AM

Declare label as new

Dim compliant As new Label 


What you are doing is like this:

Make a object of label and refer to nothing
And then you are using that nothing in your program

And sins you refer to nothings property the property is nothing itself, so it is completely nothing that you using .

A lot of nothings here :P
Was This Post Helpful? 0
  • +
  • -

#3 Krimel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-August 12

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 08:12 AM

Thank you for the tip, but that did not solve my problem, I have tried this in the past as well as placing the public sub in a behindcode file, using trycast, directcast, Ctype and anything else i could find as a reference to findcontrol. In addition, if I comment out the [compliant = TryCast(FormView1.FindControl("label1"), Label)] line and simply assign a test string to my variable everything works correctly, even after I uncomment this line and comment out the assigned test string.
[compliant = DirectCast(FormView1.FindControl("label1"), Label)
' compliant.Text = "Yes"]
as it reads label1 from the formview correctly as long as I do not refresh my browser. Once I refresh my browser or open app in a new window, I recive the null error message.
I have tried this code in a different project thinking the web.config file has something screwed up as well as running it on a older version of IIS, still nothing and everything points back to this line as the common factor. [compliant = DirectCast(FormView1.FindControl("label1"), Label)
Was This Post Helpful? 0
  • +
  • -

#4 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 08:37 AM

are you sure there is label1? and is not empty??
Did you tried debug it??
Was This Post Helpful? 0
  • +
  • -

#5 Krimel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-August 12

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 08:49 AM

Positive a Label1 exists as again, I can run the code by hard coding the variable, and then comment that out and use by findcontrol line and the app works exactly as I want it to, until I refresh my browser. and No I have not run a debug yet.

here is the full error:
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 15: 'compliant.Text = "Yes"
Line 16:
Line 17: If compliant.Text = "Yes" Then
Line 18: TextBox2.Text = " Yes you passed"
Line 19: ElseIf compliant.Text = "No" Then


Source File: C:\inetpub\wwwroot\db\employeedirectory\employeedirectory\employeetraining.aspx Line: 17

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
ASP.db_employeedirectory_employeedirectory_employeetraining_aspx.FormView1_DataBound(Object sender, EventArgs e) in C:\inetpub\wwwroot\db\employeedirectory\employeedirectory\employeetraining.aspx:17
System.Web.UI.WebControls.BaseDataBoundControl.OnDataBound(EventArgs e) +97
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +140
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.FormView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.FormView.EnsureDataBound() +166
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
Was This Post Helpful? 0
  • +
  • -

#6 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 09:25 AM

System.NullReferenceException: Object reference not set to an instance of an object.

Hmm I am 99% that you didnít declared some things the right way
My guess would be compliant variable but sins you added the new key word hmm
Can you show me the code where you data bound the form?
Was This Post Helpful? 0
  • +
  • -

#7 Krimel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-August 12

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 09:29 AM

here is my code

[<ItemTemplate>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<table border="1" cellspacing="1" class="style10">
<tr>
<td class="style19">
<b>Name:</b>&nbsp;</td>
<td class="style11">
<asp:Label ID="edd_first_nameLabel" runat="server"
Text='<%# Bind("edd_first_name") %>' />
&nbsp;<asp:Label ID="edd_last_nameLabel" runat="server"
Text='<%# Bind("edd_last_name") %>' />
</td>
<td class="style13">
<b>Employee ID#</b></td>
<td class="style17">
<asp:Label ID="Emp_IDLabel" runat="server" Text='<%# Bind("Emp_ID") %>' />
</td>
<td class="style15">
<b>Phone Ext</b></td>

<td>
<b>&nbsp;<asp:Label ID="edd_telephone_extLabel" runat="server"
Text='<%# Bind("edd_telephone_ext") %>' style="font-weight: 400" />
</b>
</td>
</tr>
<tr>
<td class="style19">
<b>Job Title:</b></td>
<td class="style11" colspan="5">
<asp:Label ID="edd_titleLabel" runat="server" Text='<%# Bind("edd_title") %>' />
</td>
</tr>
<tr>
<td class="style16" colspan="6">
&nbsp;</td>
</tr>
<tr>
<td class="style20">
Organization:</td>
<td class="style11">
<asp:Label ID="edd_organization_nameLabel" runat="server"
Text='<%# Bind("edd_organization_name") %>' />
</td>
<td class="style16">
Division:</td>
<td class="style14" colspan="3">
<b>
<asp:Label ID="edd_divisionLabel" runat="server" style="font-weight: 400"
Text='<%# Bind("edd_division") %>' />
</b>
</td>
</tr>
<tr>
<td class="style20">
Department:</td>
<td class="style11">
<b>
<asp:Label ID="edd_department_nameLabel" runat="server"
style="font-weight: 400" Text='<%# Bind("edd_department_name") %>' />
</b>
</td>
<td class="style16">
Location:</td>
<td class="style14" colspan="3">
<asp:Label ID="edd_cityLabel" runat="server" Text='<%# Bind("edd_city") %>' />
</td>
</tr>
<tr>
<td class="style12" colspan="6">
&nbsp;</td>
</tr>
<tr>
<td class="style19">
<b>Job Classificaiton</b>:</td>
<td class="style11" colspan="5">
<asp:Label ID="edd_jobclassLabel" runat="server"
Text='<%# Bind("edd_jobclass") %>' />
</td>
</tr>
</table>
<br />
<table class="style24">
<tr>
<td class="style25" bgcolor="#F7F7DE">
Is Employee in Compliance of COJET Requirment

</td>
<td bgcolor="#5D7B9D">
<asp:Label ID="Label1" runat="server"
style="color: #FFFFFF; font-weight: 700; font-style: italic"
Text='<%# Bind("edd_compliant") %>' />
</td>
</tr>
</table>
<br />
</ItemTemplate>]
Was This Post Helpful? 0
  • +
  • -

#8 DarenR  Icon User is online

  • D.I.C Lover

Reputation: 387
  • View blog
  • Posts: 2,669
  • Joined: 12-January 10

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 10:23 AM

put code in [code] tags
Was This Post Helpful? 0
  • +
  • -

#9 Krimel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-August 12

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 11:22 AM

here is the entire formview code in tags
   <asp:FormView ID="FormView1" runat="server" DataSourceID="emptrainingmain" 
            CellPadding="4" ForeColor="#333333" Height="196px" 
            Width="814px">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <EditItemTemplate>
                edd_title:
                <asp:TextBox ID="edd_titleTextBox" runat="server" 
                    Text='<%# Bind("edd_title") %>' />
                <br />
                edd_telephone_ext:
                <asp:TextBox ID="edd_telephone_extTextBox" runat="server" 
                    Text='<%# Bind("edd_telephone_ext") %>' />
                <br />
                Emp_ID:
                <asp:TextBox ID="Emp_IDTextBox" runat="server" Text='<%# Bind("Emp_ID") %>' />
                <br />
                edd_first_name:
                <asp:TextBox ID="edd_first_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_first_name") %>' />
                <br />
                edd_division:
                <asp:TextBox ID="edd_divisionTextBox" runat="server" 
                    Text='<%# Bind("edd_division") %>' />
                <br />
                edd_last_name:
                <asp:TextBox ID="edd_last_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_last_name") %>' />
                <br />
                edd_department_name:
                <asp:TextBox ID="edd_department_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_department_name") %>' />
                <br />
                edd_organization_name:
                <asp:TextBox ID="edd_organization_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_organization_name") %>' />
                <br />
                edd_jobclass:
                <asp:TextBox ID="edd_jobclassTextBox" runat="server" 
                    Text='<%# Bind("edd_jobclass") %>' />
                <br />
                edd_city:
                <asp:TextBox ID="edd_cityTextBox" runat="server" 
                    Text='<%# Bind("edd_city") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                edd_title:
                <asp:TextBox ID="edd_titleTextBox" runat="server" 
                    Text='<%# Bind("edd_title") %>' />
                <br />
                edd_telephone_ext:
                <asp:TextBox ID="edd_telephone_extTextBox" runat="server" 
                    Text='<%# Bind("edd_telephone_ext") %>' />
                <br />
                Emp_ID:
                <asp:TextBox ID="Emp_IDTextBox" runat="server" Text='<%# Bind("Emp_ID") %>' />
                <br />
                edd_first_name:
                <asp:TextBox ID="edd_first_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_first_name") %>' />
                <br />
                edd_division:
                <asp:TextBox ID="edd_divisionTextBox" runat="server" 
                    Text='<%# Bind("edd_division") %>' />
                <br />
                edd_last_name:
                <asp:TextBox ID="edd_last_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_last_name") %>' />
                <br />
                edd_department_name:
                <asp:TextBox ID="edd_department_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_department_name") %>' />
                <br />
                edd_organization_name:
                <asp:TextBox ID="edd_organization_nameTextBox" runat="server" 
                    Text='<%# Bind("edd_organization_name") %>' />
                <br />
                edd_jobclass:
                <asp:TextBox ID="edd_jobclassTextBox" runat="server" 
                    Text='<%# Bind("edd_jobclass") %>' />
                <br />
                edd_city:
                <asp:TextBox ID="edd_cityTextBox" runat="server" 
                    Text='<%# Bind("edd_city") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<table border="1" cellspacing="1" class="style10">
                    <tr>
                        <td class="style19">
                            <b>Name:</b>&nbsp;</td>
                        <td class="style11">
                            <asp:Label ID="edd_first_nameLabel" runat="server" 
                                Text='<%# Bind("edd_first_name") %>' />
                            &nbsp;<asp:Label ID="edd_last_nameLabel" runat="server" 
                                Text='<%# Bind("edd_last_name") %>' />
                        </td>
                        <td class="style13">
                            <b>Employee ID#</b></td>
                        <td class="style17">
                            <asp:Label ID="Emp_IDLabel" runat="server" Text='<%# Bind("Emp_ID") %>' />
                        </td>
                        <td class="style15">
                            <b>Phone Ext</b></td>
                            
                        <td>
                            <b>&nbsp;<asp:Label ID="edd_telephone_extLabel" runat="server" 
                                Text='<%# Bind("edd_telephone_ext") %>' style="font-weight: 400" />
                            </b>
                        </td>
                    </tr>
                    <tr>
                        <td class="style19">
                            <b>Job Title:</b></td>
                        <td class="style11" colspan="5">
                            <asp:Label ID="edd_titleLabel" runat="server" Text='<%# Bind("edd_title") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td class="style16" colspan="6">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style20">
                            Organization:</td>
                        <td class="style11">
                            <asp:Label ID="edd_organization_nameLabel" runat="server" 
                                Text='<%# Bind("edd_organization_name") %>' />
                        </td>
                        <td class="style16">
                            Division:</td>
                        <td class="style14" colspan="3">
                            <b>
                            <asp:Label ID="edd_divisionLabel" runat="server" style="font-weight: 400" 
                                Text='<%# Bind("edd_division") %>' />
                            </b>
                        </td>
                    </tr>
                    <tr>
                        <td class="style20">
                            Department:</td>
                        <td class="style11">
                            <b>
                            <asp:Label ID="edd_department_nameLabel" runat="server" 
                                style="font-weight: 400" Text='<%# Bind("edd_department_name") %>' />
                            </b>
                        </td>
                        <td class="style16">
                            Location:</td>
                        <td class="style14" colspan="3">
                            <asp:Label ID="edd_cityLabel" runat="server" Text='<%# Bind("edd_city") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td class="style12" colspan="6">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style19">
                            <b>Job Classificaiton</b>:</td>
                        <td class="style11" colspan="5">
                            <asp:Label ID="edd_jobclassLabel" runat="server" 
                                Text='<%# Bind("edd_jobclass") %>' />
                        </td>
                    </tr>
                </table>
                <br />
                <table class="style24">
                    <tr>
                       <td class="style25" bgcolor="#F7F7DE">
                            Is Employee in Compliance of COJET Requirment
                           
                        </td>
                        <td bgcolor="#5D7B9D">
                            <asp:Label ID="Label1" runat="server" 
                                style="color: #FFFFFF; font-weight: 700; font-style: italic" 
                                Text='<%# Bind("edd_compliant") %>' />
                        </td>
                    </tr>
                </table>
                <br />
            </ItemTemplate>
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
        </asp:FormView>
     

Was This Post Helpful? 0
  • +
  • -

#10 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 11:43 AM

I think it is safe to say that there is nothing wrong with these codes.
Now can you post vb.net codes that you using?
Was This Post Helpful? 0
  • +
  • -

#11 Krimel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-August 12

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 04:03 PM

Thank you for your help, but I think I have found my answer, I am pulling in the formview results from a TextBox, which a user populates and submits. My problem was I left a default value off of this text box. Once I entered a default value into the text box the sub works perfectly.

thanks again
Was This Post Helpful? 0
  • +
  • -

#12 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: I am trying to pull a value from a formview into a text box

Posted 16 August 2012 - 11:55 PM

Sometimes even 1 character can make you get headaches
Was This Post Helpful? 1
  • +
  • -

#13 miguel879  Icon User is offline

  • New D.I.C Head

Reputation: 10
  • View blog
  • Posts: 40
  • Joined: 20-July 12

Re: I am trying to pull a value from a formview into a text box

Posted 17 August 2012 - 12:46 AM

TextBox1.Text = ListView1.FocusedItem.SubItems(0).text

hope it helps..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1