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

RadComboBox Data Clear??

3 Answers 154 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 14 Nov 2008, 04:28 AM
Hi there,

I have two combobox, infoCat and childCat
When the ParentCombo selectedindex is changed, I want ChildCombo to re-databind (as the data is obtained through the database).

I'm having a difficulty with this. On other post, you said that I can use ItemsRequested event.. But it seems the demo code is outdated..
the script in the aspx file doesn't make sense..


within ASPX.VB File:

 

Protected Sub infoCat_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.WebControls.RadComboBoxSelectedIndexChangedEventArgs) Handles infoCat.SelectedIndexChanged

 

PopulateChildIDs()

 

End Sub

 

Protected Sub infoCat_ItemsRequested(ByVal o As Object, ByVal e As Telerik.WebControls.RadComboBoxItemsRequestedEventArgs) Handles infoCat.ItemsRequested

 

PopulateInfoIDs()

 

End Sub

 

 

Protected Sub childCat_ItemsRequested(ByVal o As Object, ByVal e As Telerik.WebControls.RadComboBoxItemsRequestedEventArgs) Handles childCat.ItemsRequested

 

PopulateChildIDs()

 

End Sub

 


Private

Sub PopulateInfoIDs()

 

sql =

"SELECT category, category As value FROM InfoCategory"

 

dbCommand = db.GetSqlStringCommand(sql)

 

Dim ds As DataSet = db.ExecuteDataSet(dbCommand)

 

infoCat.DataSource = ds

infoCat.DataTextField =

"category"

 

infoCat.DataValueField =

"value"

 

infoCat.DataBind()

 

If infoCat.Items.Count > 0 Then

 

infoCat.SelectedIndex = 0

 

End If

 


 

Private Sub PopulateChildIDs()

 

 

If infoCat.SelectedIndex <> -1 Then

 

sql =

"SELECT title, title As value FROM Information WHERE category ='" & infoCat.SelectedValue & "'"

 

dbCommand = db.GetSqlStringCommand(sql)

 

Dim ds As DataSet = db.ExecuteDataSet(dbCommand)

 

childCat.DataSource = ds

childCat.DataTextField =

"title"

 

childCat.DataValueField =

"value"

 

childCat.DataBind()

 

If childCat.Items.Count > 0 Then

 

childCat.SelectedIndex = -1

 

End If

 


On ASPX File:

 

<div class="editdropdown2">

 

 

<radC:RadComboBox ID="infoCat" runat="server" AutoPostBack="True" Skin="ClassicBlue" Width="582px">

 

 

</radC:RadComboBox>

 

 

<radC:RadComboBox ID="childCat" runat="server" AutoPostBack="True" Skin="ClassicBlue" Width="582px" OnClientItemsRequested="ItemsLoaded">

 

 

</radC:RadComboBox>

 

 

</div>

 


I tried using script

 

<script type="text/javascript">

 

 

var childCombo = <%= childCat.ClientID %>;

 

 

function PopulateChildIDs(item)

 

{

childCombo.SetText(

"Loading...");

 

childCombo.RequestItems(item.Value,

false);

 

}

 

 

function ItemsLoaded(combo)

 

{

 

if (combo.Items.length > 0)

 

{

combo.SetText(combo.Items[0].Text);

combo.Items[0].Highlight();

}

combo.ShowDropDown();

}

 

</script>

 


but not working. How come in the demo it uses (item) <-- where is the argument used..?

Can you provide me some guidance/script/solution to this?

Thanks,

Andreas

3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 17 Nov 2008, 09:37 AM
Hello Andreas,

You actually do not need to handle the OnSelectedIndexChanged server-side event to achieve this functionality.

Please handle the OnClientSelectedIndexChanged event with the PopulateChildIDs function on the client.

Please notice that in this live demo the server-side code is for populating the ComboBoxes on the page. The actual AJAX callbacks are initiated on the client and the post-AJAX work is also done there.

I hope this helps.

Regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andreas
Top achievements
Rank 1
answered on 17 Nov 2008, 12:35 PM
Thanks Simon.

I actually did that today. i.e :
...

<radC:RadComboBox ID="infoCat" runat="server" AutoPostBack="True" Skin="ClassicBlue"  Width="582px" OnClientSelectedIndexChanged ="LoadChild"> </radC:RadComboBox>

<radC:RadComboBox ID="childCat" runat="server" AutoPostBack="True" Skin="ClassicBlue" Width="582px" OnClientItemsRequested="ItemsLoaded" OnItemsRequested="childCat_ItemsRequested" > </radC:RadComboBox>

...

CodeBehind:

Protected Sub childCat_ItemsRequested(ByVal o As Object, ByVal e As Telerik.WebControls.RadComboBoxItemsRequestedEventArgs) Handles childCat.ItemsRequested

{PopulateChildIDs()}

End Sub

in the script:

<script type="text/javascript">                                    OK

var childCombo = <%= childCat.ClientID %>;               OK

function LoadChild(item)                

{

childCombo.SetText("Loading...");                               OK    

childCombo.RequestItems(item.Value,false);                <-- NO VALUE..?

}

...

It finally shows the text 'Loading', and it seems requesting item, but return blank...
The javascript debugging doesn't show any error. The childbox doesn't show the items (it should bind the data from the db)

Since my PopulateChildIDs() doesn't take any argument, it shouldn't matter if the item.Value is empty string ("") right?
Not to mention that I tried passing in 'category' as a parameter, but it still doesn't bind any data.

It shows loading. and when I click on the child combobox, somehow there is another empty box appearing on the page with arrow up/down button.

Can you please show me where I did this thing wrong?

Cheers,

Andreas

0
Simon
Telerik team
answered on 19 Nov 2008, 05:42 PM
Hello Andreas,

Your code seems OK so far. I am not sure why this could be happening on your end and a further investigation is required in this case.

Please open a formal support ticket and send us the project there to inspect it.

Thank you in advance for your co-operation and understanding.

Kind regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Andreas
Top achievements
Rank 1
Answers by
Simon
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or