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

Binding to a RadTextBox

7 Answers 830 Views
Input
This is a migrated thread and some comments may be shown as answers.
Stephen Cossgrove
Top achievements
Rank 1
Stephen Cossgrove asked on 18 Nov 2009, 11:43 PM
Hi,

I'm a newbie to Telerik controls and i am having and issue with trying to bind to a object/datasource.

Every example i am seeing is binding to a datagrid but i do want this. I have a few controls on the page and nothing seem to have any property to set a datasource or datamember for data binding.

Can anyonje tell me how i can do this or point me to a resource that can show me?

thanks,
Stephen

7 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Nov 2009, 02:14 PM
Hello Stephen,

You can bind RadTextBox in the same way as the regular ASP.NET TextBox control:
Binding ObjectDataSource control to a asp:TextBox

<telerik:RadTextBox ID="RadTextBox1" runat="server" Text="<%# Bind("Something") %>">
</telerik:RadTextBox>

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Pavol
Top achievements
Rank 1
answered on 18 Apr 2013, 09:21 PM

Hi,

I am very new to Telerik and not an ASPX expert to boot.

I would really appreciate if you could spoon-feed me here a bit:

I have a webpage which has a RadTextBox and a RadButton styled as a Checkbox:

...
<telerik:RadTextBox ID="RadTextBoxEmailSubject" runat="server"  Width="220px" Text="<%# Bind("report_group_subject") %>">
</telerik:RadTextBox>
<!--telerik:RadTextBox-- ID="RadTextBoxEmailSubject" runat="server"  Width="220px"
    DataSourceID="SqlDataSourceGroupWhere" DataTextField="report_group_subject" DataValueField="report_group_id">
</telerik:RadTextBox-->
...
<td>
<telerik:RadButton ID="RadButtonCombineFile" runat="server" Text="" ToggleType="CheckBox" ButtonType="ToggleButton"
    DataSourceID="SqlDataSourceGroupWhere" DataTextField="combine_toggle" DataValueField="report_group_id">
</telerik:RadButton>
...

The first RadTextBox section, done based on your answer to the original question of this thread, gives me an: Error 1 The server tag is not well formed. error, plus I do not see how is the binding to the SqlDataSource done here.
The commented out section for the RadTextBox, as well as the section for the Checkbox style RadButton did not work, I wrote them in a hope that I can copy the RadComboBox binding style. I am binding the RadComboBox and some other controls to an SqlDataSource, which works fine, like this:

...
<telerik:RadComboBox ID="RadComboBoxEmailType" runat="server" Height="50px"  Width="120px"
    Filter="Contains" MarkFirstMatch="True" ChangeTextOnKeyBoardNavigation="False"
    DataSourceID="SqlDataSourceGroupWhere" DataTextField="email_type" DataValueField="report_group_id"
    Skin="Office2010Silver">
</telerik:RadComboBox>
...
<asp:SqlDataSource
    ID="SqlDataSourceGroupWhere"
    runat="server"
    ConnectionString="<%$ ConnectionStrings:SEG_WebConnectionString %>"
    SelectCommand="SELECT DISTINCT [report_group_name], [report_group_id], [report_group_subject], [email_type], [combine_toggle], [combine_outfile] FROM [Axys_Group_Of_Reports] WHERE ([report_group_id] = @report_group_id)">
    <SelectParameters>
        <asp:ControlParameter ControlID="RadComboBoxReportGroup" Name="report_group_id" PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
...

 

I would much appreciate if you could let me know the correct code to bind the RadTextBox, as well as the Checkbox style RadButton to an SQLDataSource.

Thank you very much,

Pavol

 

 

 

 

 


0
Shinu
Top achievements
Rank 2
answered on 19 Apr 2013, 03:53 AM
Hi,

You can bind the value as shown below.
aspx:
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%#Eval("ID")%>'></telerik:RadTextBox>
<telerik:RadButton ID="RadButton1" runat="server" ToggleType="CheckBox" ButtonType="ToggleButton" Checked='<%# Bind("Value") %>'>
</telerik:RadButton>

Thanks,
Shinu
0
Pavol
Top achievements
Rank 1
answered on 19 Apr 2013, 12:11 PM
Shinu, Thank you for your reply. I however forgot to mention that I am trying to bind the controls using an SQLDataSource, so for example, when I am binding a RadComboBox,, the correct, working code looks like this:
<telerik:RadComboBox ID="RadComboBoxReportGroup" runat="server" Height="50px"  Width="120px"
    Filter="Contains" MarkFirstMatch="True" ChangeTextOnKeyBoardNavigation="False" AutoPostBack ="True"
    DataSourceID="SqlDataSourceGroup" DataTextField="report_group_name" DataValueField="report_group_id"
    Skin="Office2010Silver">
</telerik:RadComboBox>

I am guessing that you are using the Telerik specific method which uses NeedDataSource event. I did not familiarize myself with this yet.
So, could you please let me know if there is a way to do this via binding to an SQLDataSource?
Also I would much appreciate, if you could please use my concrete variables in your example, instead of generic ones, or at least specify which strings need to be replaced with what, since I am not sure if I should replace things like "Value" and "ID" with some things of my own at this current stage of "un-knowing." Thank you again Shinu, and whoever else would volunteer to help me with this! Happy Friday!
0
Shinu
Top achievements
Rank 2
answered on 22 Apr 2013, 04:34 AM
Hi,

You can replace the Value and ID fields with the one in your database. In order to bind the grid with datasource, try the following code.
aspx:
<telerik:RadGrid  ID="RadGrid5" AutoGenerateColumns="true" runat="server" DataSourceID="SqlDataSource2" AutoGenerateEditColumn="true" >
</telerik:RadGrid>

Thanks,
Shinu
0
Pavol
Top achievements
Rank 1
answered on 22 Apr 2013, 02:32 PM
Hi Shinu, your answer seems to be about a grid, while my question is NOT.

My question is, PLEASE read carefully:

How to bind a RadTextBox and Checkbox style RadButton to an SqlDataSource

Please be specific and only provide the needed and necessary code.

Please use these concrete control names in your answer:

RadTextBox1RadButton1, SqlDataSource1, and if needed  SqlDataSource2
0
Shinu
Top achievements
Rank 2
answered on 23 Apr 2013, 04:20 AM
Hi,

Here is the full code that I tried.
aspx:
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%#Eval("ID")%>'></telerik:RadTextBox>
<telerik:RadButton ID="RadButton1" runat="server" ToggleType="CheckBox" ButtonType="ToggleButton" Checked='<%# Bind("Value") %>'>
</telerik:RadButton>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="select top 5 *  from [Orders]"></asp:SqlDataSource>

Thanks,
Shinu
Tags
Input
Asked by
Stephen Cossgrove
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Pavol
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or