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

[Solved] loadon demand

3 Answers 132 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Support ATT
Top achievements
Rank 1
Support ATT asked on 03 Jun 2008, 09:17 PM
I have an combobox with loadondemnand, this works perfect, when the user clicks the combobox .

now, i have to set the text of the combobox in code-behind (preselect)

radcombobox.text = "Basketball"

How can i call now the itemsrequest methode correct, with the argument of the 
RadComboBoxItemsRequestedEventArgs ?

protected void ddlSport_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs

3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 04 Jun 2008, 07:31 AM
Hi Toprak Abdullah,

Why don't you move the loading Items logic from the ItemsRequested event handler into a separate routine with only one argument: the text that is being searched for? In this way, you can call this routine whenever necessary, or as in your case when you set the Text of the ComboBox.

Consider the following code:

    protected void Page_Load(object sender, EventArgs e) 
    { 
        RadComboBox1.Text = "Basketball"
 
        LoadItems(RadComboBox1.Text); 
    } 
 
    private void LoadItems(string text) 
    { 
        //Load Items... 
    } 
 
    protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) 
    { 
        LoadItems(e.Text); 
    } 

Best wishes,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Support ATT
Top achievements
Rank 1
answered on 04 Jun 2008, 06:27 PM

this is a good idea, which i have also thought about. but how should i set the value for:

LoadItems(RadComboBox1.Text); 

e.Message or e.EndOfItems = true; ???

DataTable data = DBManager.getInstance().getSportNames(e.Text);

try

{

int itemsPerRequest = 15;

int itemOffset = e.NumberOfItems;

int endOffset = itemOffset + itemsPerRequest;

if (endOffset > data.Rows.Count)

{

endOffset = data.Rows.Count;

}

if (endOffset == data.Rows.Count)

{

e.EndOfItems =

true;

}

else

{

e.EndOfItems =

false;

}

for (int i = itemOffset; i < endOffset; i++)

{

ddlSport.Items.Add(

new RadComboBoxItem(data.Rows[i]["Name"].ToString(), data.Rows[i]["SportsID"].ToString()));

}

if (data.Rows.Count > 0)

{

e.Message =

String.Format("Sportarten <b>1</b>-<b>{0}</b> von <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());

}

else

{

e.Message =

"Keine Eintr„ge gefunden";

}

}

catch

{

e.Message =

"Keine Eintr„ge gefunden";

}

0
Simon
Telerik team
answered on 09 Jun 2008, 01:20 PM
Hi Toprak Abdullah,

In this case you could change the approach a little bit:

    protected void Page_Load(object sender, EventArgs e) 
    { 
        RadComboBox1.Text = "Basketball"
 
        RadComboBox1.DataSource = GetItems("Basketball"); 
        RadComboBox1.DataBind(); 
    } 
 
    private DataTable GetItems(string text) 
    { 
        return DBManager.getInstance().getSportNames(e.Text); 
    } 
 
    protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) 
    { 
        DataTable data = LoadItems(e.Text); 
 
        //... 
    } 

Moreover, you could bind the ComboBox in Page_Load only to the first N results, similarly as in the ItemsRequested event handler, depending on your requirements.

Greetings,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Support ATT
Top achievements
Rank 1
Answers by
Simon
Telerik team
Support ATT
Top achievements
Rank 1
Share this question
or