This is a migrated thread and some comments may be shown as answers.

Simple bind textbox in code behind?

2 Answers 194 Views
Input
This is a migrated thread and some comments may be shown as answers.
Ted
Top achievements
Rank 1
Ted asked on 26 Jun 2013, 03:44 AM
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 asp.net 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?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 28 Jun 2013, 11:20 AM
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:

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

VB:
RadTextBox1.Text = "Some text"

Regards,
Angel Petrov
Telerik
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.
0
Ted
Top achievements
Rank 1
answered on 28 Jun 2013, 10:06 PM
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")
Tags
Input
Asked by
Ted
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Ted
Top achievements
Rank 1
Share this question
or