Simple bind textbox in code behind?

3 posts, 0 answers
  1. Ted
    Ted avatar
    5 posts
    Member since:
    May 2013

    Posted 25 Jun 2013 Link to this post

    I cannot find a complete example. Found tons on grid and combobox, but not textbox. This test is to lookup a “PhoneTypeName” from a UserPhoneType table with TypeCode = “0” and assign that first value to a textbox.

    Currently, I am getting “Object reference not set to an instance of an object” when setting the text box to "phonetype.FirstOrDefault.PhoneTypeName.ToString"

    Using dbContext As New EntitiesModel()
        Dim phonetype As IEnumerable(Of User_PhoneType) = dbContext.User_PhoneTypes.Where(Function(c) c.PhoneTypeCode = "O")
        mytextbox.Text = phonetype.FirstOrDefault.PhoneTypeName.ToString
    End Using

    Also, would binding work any differently in this case if this were a radtextbox?

  2. Angel Petrov
    Angel Petrov avatar
    1039 posts

    Posted 28 Jun 2013 Link to this post

    Hello Ted,

    Could you ensure that the phonetype collection returned as a result is not null? Other than that I do not see anything that can cause this behavior. Also I noticed that the TypeCode is set to O instead of zero. Could you please elaborate more on the requirement? Should the TypeCode be zero or "O"? As for setting the text of a RadTextBox it is the same as setting the text of an ASP.NET text box. Example:

    <telerik:RadTextBox runat="server" ID="RadTextBox1"></telerik:RadTextBox>

    RadTextBox1.Text = "Some text"

    Angel Petrov
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. Ted
    Ted avatar
    5 posts
    Member since:
    May 2013

    Posted 28 Jun 2013 Link to this post

    FIXED: Yes, the type is the letter O and not a zero. Therefore, I had to add "ToString" to my query like this.

    ...= dbContext.User_PhoneTypes.Where(Function(c) c.PhoneTypeCode**.ToString** = "O")
Back to Top