Binding to a RadTextBox

8 posts, 0 answers
  1. Stephen Cossgrove
    Stephen Cossgrove avatar
    7 posts
    Member since:
    Nov 2009

    Posted 18 Nov 2009 Link to this post

    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
  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 19 Nov 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pavol
    Pavol avatar
    3 posts
    Member since:
    Mar 2013

    Posted 18 Apr 2013 Link to this post

    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

     

     

     

     

     


  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Apr 2013 Link to this post

    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
  6. Pavol
    Pavol avatar
    3 posts
    Member since:
    Mar 2013

    Posted 19 Apr 2013 Link to this post

    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!
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Apr 2013 Link to this post

    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
  8. Pavol
    Pavol avatar
    3 posts
    Member since:
    Mar 2013

    Posted 22 Apr 2013 Link to this post

    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
  9. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Apr 2013 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017