Good Day Guys , i am using RadSilverlight controls and the implementation should be the same with the normal Combobox. But now the List that i get is not what i want or the data that i need. i have a WCF DataLayer Service that has a function that is defined like this
public
IList<AccountsModel> GetAccounts()
{
con =
new
SqlConnection(strConccounting);
cmdselect =
new
SqlCommand(
"usp_Select_Account"
);
cmdselect.CommandType = CommandType.StoredProcedure;
da =
new
SqlDataAdapter();
cmdselect.Connection = con;
da.SelectCommand = cmdselect;
DataTable dt =
new
DataTable();
List<AccountsModel> m_Accounts =
new
List<AccountsModel>();
try
{
con.Open();
da.Fill(dt);
if
(dt.Rows.Count > 0)
{
for
(
int
i = 0; i < dt.Rows.Count; i++)
{
AccountsModel m =
new
AccountsModel();
m.iAccountID = Convert.ToInt32(dt.RowsIdea[0]);
m.sName = dt.RowsIdea[1].ToString();
m_Accounts.Add(m);
}
}
}
catch
(SqlException ex)
{
throw
ex;
}
finally
{
con.Close();
}
return
m_Accounts;
}
and now in my Presentation Layer, my Silverlight App , i want to Bind it to the Combobox. Now normally in asp.net . you would have e.g
ID , that will be Primary key for the record and the "Description" and that will be the Text that will be displayed in the the Dropdownlist. So my setup is the same and i have amodel that is sitting on the Data layer that i forgot to share with you
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.ComponentModel;
using
System.ServiceModel;
using
System.Runtime.Serialization;
namespace
DAL
{
public
class
AccountsModel : INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler PropertyChanged;
private
int
_iAccountID;
private
string
_sName;
/// When the Property is changed from the PL this gets Fired
/// </summary>
/// <param name="property"></param>
private
void
OnPropertyChanged(String property)
{
// DAL objConverter = new DAL();
List<AccountsModel> Model =
new
List<AccountsModel>();
if
(PropertyChanged !=
null
)
{
PropertyChanged(
this
,
new
PropertyChangedEventArgs(property));
//objConverter.Updatedata();
}
}
public
int
iAccountID
{
get
{
return
_iAccountID;
}
set
{
_iAccountID = value;
OnPropertyChanged(
"iAccountID"
);
}
}
public
string
sName
{
get
{
return
_sName;
}
set
{
_sName = value;
OnPropertyChanged(
"sName"
);
}
}
}
}
ok now lets Continue. Now on the Silverlight side , i had a Telerik Combobox that is defined like this in the xaml
<
telerik:RadComboBox
HorizontalAlignment
=
"Left"
Text
=
"{Binding sName}"
Margin
=
"222,80,0,0"
Name
=
"ddlaccount"
VerticalAlignment
=
"Top"
Width
=
"186"
Height
=
"26"
>
</
telerik:RadComboBox
>
and the server side i am creating the BLL Service object and accessing the funtions like this
public
Posting()
{
InitializeComponent();
Loaded +=
new
RoutedEventHandler(Posting_Loaded);
}
void
Posting_Loaded(
object
sender, RoutedEventArgs e)
{
BLL.BLLServiceClient objBLL =
new
BLL.BLLServiceClient();
objBLL.GetAccountsCompleted +=
new
EventHandler<BLL.GetAccountsCompletedEventArgs>(objBLL_GetAccountsCompleted);
objBLL.GetAccountsAsync();
}
void
objBLL_GetAccountsCompleted(
object
sender, BLL.GetAccountsCompletedEventArgs e)
{
if
(e.Error ==
null
)
{
ddlaccount.ItemsSource = e.Result;
}
}
and at the same time , i am binding the Combobox. but the Results i get are not the Values but this
Thanks