Urgent: Help with adding new items to sql server database inside a RadComboBox

3 posts, 0 answers
  1. Mike
    Mike avatar
    24 posts
    Member since:
    Jul 2008

    Posted 12 Jun 2010 Link to this post

    Hi all,

    I have been playing around with the possibility of enabling users to enter a new url into a radcombobox if it doesn't exist in list already. I have the following markup in my grid <FormTemplate> which pulls its data from a table named tblUrls:

    <telerik:RadComboBox ID="UrlComboBox"  
                         runat="server"  
                         HighlightTemplatedItems="true" 
                         AllowCustomText="true"  
                         Skin="Windows7"  
                         Width="365px"  
                         Height="150px"  
                         DataSourceID="UrlDataSource"  
                         DataTextField="Url"  
                         DataValueField="Url" 
                         SelectedValue='<%# Bind("Url") %>'  
                         AppendDataBoundItems="true">

    <Items> 
            <telerik:RadComboBoxItem Text="[Not Defined]" Value="" /> 
        </Items> 
        <FooterTemplate> 
            <telerik:RadTextBox ID="tbNewUrl" runat="server" Skin="Windows7" EmptyMessage="Add a new Url here..."/> 
            <br /> 
            <asp:Button ID="AddUrlBtn" runat="server" Text="Add Url" OnClick="AddUrlBtn_Click" /> 
        </FooterTemplate>

    </
    telerik:RadComboBox> 

    I have tried getting access to the tbNewUrl radtextbox inside the RadComboBox in the c# code behind to no avail. I need the AddUrlBtn_Click to save whatever value is put in by the user to the database when the grid is in insert or edit mode. I have the database INSERT code already worked out but getting access to the RadComboBox and the newly inputted url data is proving to be a real pain. I am sure it is real simple, but patience has run out on this one and I am forced to try another way of doing this if I can;t get it resolved quickly.

    I have tried:

    protected void AddUrlBtn_Click(object sender, EventArgs e) 
        TextBox Urltxt = (TextBox)UrlComboBox.Footer.FindControl("tbNewUrl"); 

    if ((!String.IsNullOrEmpty(Urltxt.Text))&&(UrlComboBox.FindItemByText(Urltxt.Text) == null)) 
        { 
            UrlComboBox.Items.Insert(0, new RadComboBoxItem(Urltxt.Text)); 
            UrlComboBox.SelectedIndex = 0
            Urltxt.Text = String.Empty; 
        }
    }

    I have also tried:

    TextBox AddUrlText = (TextBox)this.Page.Master.FindControl("ContentPlaceHolder").FindControl("tbNewUrl"); 

    inside the buttons click event - AddUrlBtn_Click but it can't find the control???

    The grid is ajaxified too but when I click the AddUrlBtn in its current condition the page does a full postback as well whilst in insert/edit mode which is undesirable.

    Any help with this would be greatly appreciated to I can move on with this project.

    Thanks in advance for any help :)
  2. Mike
    Mike avatar
    24 posts
    Member since:
    Jul 2008

    Posted 13 Jun 2010 Link to this post

    Hi all,

    I have added this post to another thread that is more along the lines of what I am trying to achieve:


    If you can help, please add to the other post, thank you :)
  3. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 15 Jun 2010 Link to this post

    Hello Grant,

    Please take a look at this forum post  for solution.

    Best wishes,
    Veronica Milcheva
    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.
Back to Top