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

Radlistbox - datatextfield

1 Answer 136 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Ayesha
Top achievements
Rank 1
Ayesha asked on 17 Nov 2009, 07:20 PM

Hi,

I've a radlistbox and I set the datasource:

 List<CMListItem> obCMListItem = new List<CMListItem>(); (where CMListItem is a class).

m_radListBox.DataSource = obCMListItem.

This obCMlistItem has ItemName,Itemdescription and Item code as 3 elements.

I need to set my datatextfield of the radlistbox by combining the 2 elements of the class( combining ItemName and Itemdescription).

If I try to do the below approach, I get an error:

            m_radInstitutionLstBox.DataTextField  = String.Format("{0},{1}", Properties.Resources.Ttl_Col_ItemName , Properties.Resources.Ttl_Col_ItemDescription);
            m_radInstitutionLstBox.DataValueField = Properties.Resources.Ttl_Col_ItemName;
            m_radInstitutionLstBox.DataSource     = obCMListItem;
            m_radInstitutionLstBox.DataBind();

How can i handle this situation. Pls help me with code in c#

Thanks,
ZR

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 18 Nov 2009, 05:14 PM
Hello Zaheka,

Please read more about the Data[...]Field properties usage (and how to resolve the issue) here.

As for your requirement, you could achieve it by handling the ItemDataBound event as shown below:

protected void m_radInstitutionLstBox_ItemDataBound(object sender, RadListBoxItemEventArgs e)
{
   CMListItem dataItem = (CMListItem)e.Item.DataItem;
   //setting different properties for the items
   e.Item.Text = tring.Format("{0},{1}", dataItem.ItemName, dataItem.Itemdescription);
}

Note: In this case you could skip setting the DataTextField property as you will be manually setting the Text property in the ItemDataBound event handler.

All the best,
Simon
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
ListBox
Asked by
Ayesha
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or