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

[Solved] Value of the SelectedItem required in Load on demand combo box

1 Answer 80 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kishan A
Top achievements
Rank 1
Kishan A asked on 26 Oct 2009, 03:19 PM
Hi,
    I have used the code of Telerik's Load on demand Combo box. I am trying to fecth the value of the SelectedItem,which I failed to fetch. Please see my code below and suggest me the solution.

[

WebMethod]

 

 

public static RadComboBoxData GetCompanyNames(RadComboBoxContext context)

 

{

 

DataSet data = GetData(context.Text);

 

 

RadComboBoxData comboData = new RadComboBoxData();

 

 

int itemOffset = context.NumberOfItems;

 

 

int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Tables[0].Rows.Count);

 

comboData.EndOfItems = endOffset == data.Tables[0].Rows.Count;

 

List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(endOffset - itemOffset);

 

 

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

 

{

 

RadComboBoxItemData itemData = new RadComboBoxItemData();

 

itemData.Text = data.Tables[0].Rows[i][

"ClientName"].ToString();

 

itemData.Value = data.Tables[0].Rows[i][

"ClientId"].ToString();

 

 

result.Add(itemData);

}

comboData.Message = GetStatusMessage(endOffset, data.Tables[0].Rows.Count);

comboData.Items = result.ToArray();

 

return comboData;

 

}

 

protected void rcbClientName_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)

 

{

 

DataSet data = GetData(e.Text);

 

 

int itemOffset = e.NumberOfItems;

 

 

int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Tables[0].Rows.Count);

 

e.EndOfItems = endOffset == data.Tables[0].Rows.Count;

 

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

 

    {

 

        RadComboBoxItemData itemData = new RadComboBoxItemData();

 

        rcbClientName.Items.Add(

new RadComboBoxItem(data.Tables[0].Rows[i]["ClientName"].ToString(),

 

        data.Tables[0].Rows[i][

"ClientName"].ToString()));

 

 

 

 

    }

 

    e.Message = GetStatusMessage(endOffset, data.Tables[0].Rows.Count);

}

 

 

private static string GetStatusMessage(int offset, int total)

 

    {

 

        if (total <= 0)

 

 

            return "No Match";

 

 

            return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);

 

    }

 

private static DataSet GetData(string text)

 

    {

 

        return TaxForms.GetClientNameAndId(text);

 

    }

 

protected void btnSelectClient_Click(object sender, EventArgs e)

 

    {

        DisplaySelection(rcbClientName, txtClientId);

    }

 

private void DisplaySelection(RadComboBox name, TextBox text)

 

{

    txtClientId.Text = rcbClientName.SelectedValue;

}

 

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 29 Oct 2009, 09:57 AM
Hi Kishan A,

The SelectedValue of the combobox should work in this case. Note that the SelectedItem will be null in load on demand scenario.

Greetings,
Veselin Vasilev
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.
Tags
ComboBox
Asked by
Kishan A
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or