Hi,
I have a Radcombobox which is dinamically loaded as below:
And it's not showing the EmptyMessage. Instead it's showing directly the items from the datasource.
How can i show a ".: Choose one :." item or make it show the EmptyMessage?
I have a Radcombobox which is dinamically loaded as below:
private
void
LoadFilters()
{
ControladorInternacao controladorInternacao =
new
ControladorInternacao();
List<InternacaoSetorDTO> listaSetores = controladorInternacao.ListarTodosSetores(AmbienteConexao.Usuario().Cnes);
List<RadComboBoxItem> listaTodosSetores =
new
List<RadComboBoxItem>();
foreach
(InternacaoSetorDTO item
in
listaSetores)
{
listaTodosSetores.Add(
new
RadComboBoxItem(item.NomeSetor, item.CodInternacaoSetor.ToString()));
}
rcbFiltroSetor.DataSource = listaTodosSetores;
rcbFiltroSetor.DataValueField =
"Value"
;
rcbFiltroSetor.DataTextField =
"Text"
;
rcbFiltroSetor.DataBind();
}
And it's not showing the EmptyMessage. Instead it's showing directly the items from the datasource.
How can i show a ".: Choose one :." item or make it show the EmptyMessage?
7 Answers, 1 is accepted
0
A2H
Top achievements
Rank 1
answered on 31 Jul 2013, 02:19 PM
Hello,
Please try the below implementation
1) Set the AppendDataBoundItems property of the combobox to True
2) Add the custom item using the DataBound event of combobox like given below
PS: We are not using ItemDatabound event here, instead we are using DataBound event of RadCombobox
Thanks,
A2H
Please try the below implementation
1) Set the AppendDataBoundItems property of the combobox to True
2) Add the custom item using the DataBound event of combobox like given below
protected
void
RadComboBox5_DataBound(
object
sender, EventArgs e)
{
var combo = (RadComboBox)sender;
combo.Items.Insert(0,
new
RadComboBoxItem(
".: Choose one :."
,
string
.Empty));
}
PS: We are not using ItemDatabound event here, instead we are using DataBound event of RadCombobox
Thanks,
A2H
0
Alexandre
Top achievements
Rank 1
answered on 31 Jul 2013, 02:48 PM
But what if i'd like to show the EmptyMessage instead of adding an "empty item" ?
0
A2H
Top achievements
Rank 1
answered on 31 Jul 2013, 03:05 PM
Hello,
Please change the DataBound method like shown below to add a Empty message instead of Empty item
Thanks,
A2H
Please change the DataBound method like shown below to add a Empty message instead of Empty item
protected
void
RadComboBox5_DataBound(
object
sender, EventArgs e)
{
var combo = (RadComboBox)sender;
combo.EmptyMessage =
"Please Select a Value"
;
}
Thanks,
A2H
0
Alexandre
Top achievements
Rank 1
answered on 03 Aug 2013, 09:51 AM
Thanks, but it didn't work.
Any other solutions ?
Any other solutions ?
0
A2H
Top achievements
Rank 1
answered on 03 Aug 2013, 05:15 PM
Hello,
Please find the code which I tried and and it works fine at my end.
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
>
</
asp:ScriptManager
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
ondatabound
=
"RadComboBox1_DataBound"
>
</
telerik:RadComboBox
>
.CS Code
protected
void
Page_Load(
object
sender, EventArgs e)
{
this
.LoadCombobox();
}
private
void
LoadCombobox()
{
List<RadComboBoxItem> listCombobox =
new
List<RadComboBoxItem>();
List<TestClass> lstValues =
new
List<TestClass>();
lstValues =
this
.GetListDetails();
foreach
(TestClass item
in
lstValues)
{
listCombobox.Add(
new
RadComboBoxItem(item.TestDescription.ToString(), item.TestID));
}
RadComboBox1.DataSource = listCombobox;
RadComboBox1.DataValueField =
"Value"
;
RadComboBox1.DataTextField =
"Text"
;
RadComboBox1.DataBind();
}
public
class
TestClass
{
public
String TestID {
get
;
set
; }
public
String TestDescription {
get
;
set
; }
}
public
List<TestClass> GetListDetails()
{
List<TestClass> lstClass =
new
List<TestClass>();
TestClass objtest =
new
TestClass();
objtest.TestID =
"1"
;
objtest.TestDescription =
"Value1"
;
lstClass.Add(objtest);
TestClass objtest1 =
new
TestClass();
objtest1.TestID =
"2"
;
objtest1.TestDescription =
"Value2"
;
lstClass.Add(objtest1);
return
lstClass;
}
protected
void
RadComboBox1_DataBound(
object
sender, EventArgs e)
{
var combo = (RadComboBox)sender;
combo.EmptyMessage =
"Please Select a Value"
;
}
Unfortunately I couldn't find the reason why it’s not working for you.
Can you please provide more details.
Thanks,
A2H
0
Logan Marshall
Top achievements
Rank 2
Iron
answered on 24 Apr 2015, 08:11 PM
I have this same problem too. the empty message isn't there until you click the drop down at least once.
0
Hello Logan,
Please specify which version of our controls are you currently using. Such bug existed in previous version of our controls, when the CheckBoxes feature of the RadComboBox is enabled.
Regards,
Nencho
Telerik
Please specify which version of our controls are you currently using. Such bug existed in previous version of our controls, when the CheckBoxes feature of the RadComboBox is enabled.
Regards,
Nencho
Telerik
See What's Next in App Development. Register for TelerikNEXT.