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

How to Databind to a textbox?

1 Answer 400 Views
Input
This is a migrated thread and some comments may be shown as answers.
Sucheta Patil
Top achievements
Rank 1
Sucheta Patil asked on 21 Jun 2010, 01:38 PM
<li> 
                        <asp:Label ID="lbSurname" runat="server" Text="Surname: " AssociatedControlID="lstSurname"</asp:Label> 
                        <telerik:RadComboBox ID="lstSurname" runat="server" ReadOnly="true" DataTextField="Family" 
                            DataValueField="Family" AppendDataBoundItems="True" AllowCustomText="True" MarkFirstMatch="True" 
                            OnSelectedIndexChanged="lstSurname_SelectedIndexChanged" AutoPostBack="True" CausesValidation="False">  
                        </telerik:RadComboBox> 
                        <asp:RequiredFieldValidator ID="RFV_lstSurname" runat="server" ValidationGroup="Personal" 
                            ControlToValidate="lstSurname" ErrorMessage="Please enter Surname">*</asp:RequiredFieldValidator>                          
                    </li> 
                    <li> 
                        <asp:Label ID="lbFname" runat="server" Text="First Name: " AssociatedControlID="lstFirst"</asp:Label> 
                        <telerik:RadComboBox ID="lstFirst" runat="server" ReadOnly="true" DataTextField="First" 
                            DataValueField="First" AppendDataBoundItems="True" AllowCustomText="True" MarkFirstMatch="True" 
                            AutoPostBack="True" CausesValidation="False"   
                            onselectedindexchanged="lstFirst_SelectedIndexChanged">  
                        </telerik:RadComboBox> 
                        <asp:RequiredFieldValidator ID="RFV_lstFirst" runat="server" ValidationGroup="Personal" 
                            ControlToValidate="lstFirst" ErrorMessage="Please enter First Name">*</asp:RequiredFieldValidator>                          
                    </li> 
 
<li><asp:Label ID="lbJobTitle" runat="server" Text="Job Title:"   
                            AssociatedControlID="txtJob"></asp:Label> 
<telerik:RadTextBox ID="txtJob" runat="server" MaxLength="150" Width="200px"></telerik:RadTextBox>                                  
/li> 
In form.aspx.cs file

protected void lstFirst_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
        {  
            string First = lstFirst.SelectedItem.Text;  
            string family = lstSurname.SelectedItem.Text;  
            var query = from x in dc.tblEmp  
                        where x.First.ToLower() == First.ToLower() && x.Family.ToLower() == family.ToLower()  
                        orderby x.Family  
                        select new  
                        {  
                            Job = x.Job_Title                             
                        };          
************txtJob.Text = query;    ************  
        } 

How do I bind data to Textbox?
 I am selecting Surname and Firstname to fire query to get Job Title. I only want to display in textbox .
Can anyone help me find solution?
Thanks in advance
Sucheta

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 23 Jun 2010, 10:01 AM
Hello Sucheta,

You can bind RadTextBox in the same way as the regular ASP.NET TextBox control. Data-binding expressions are contained within <%# and %> delimiters and use the Eval and Bind functions. The Eval function is used to define one-way (read-only) binding. The Bind function is used for two-way (updatable) binding.

More info is available here:
http://www.telerik.com/help/aspnet-ajax/input_commondatabinding.html

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Input
Asked by
Sucheta Patil
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or