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

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

2 Answers 128 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 2
Mike asked on 13 Jun 2010, 02:47 AM
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 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 2
answered on 13 Jun 2010, 12:32 PM
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 :)
0
Veronica
Telerik team
answered on 15 Jun 2010, 03:08 PM
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.
Tags
ComboBox
Asked by
Mike
Top achievements
Rank 2
Answers by
Mike
Top achievements
Rank 2
Veronica
Telerik team
Share this question
or