Answered by:
Datatable binding in silverlight datagrid

Question
-
hii everyone. i m a beginner in silverlight . In my silverlight application i have a datagrid to patient list. for this list i have created a WCF wef service which returns a datatable as follows:
namespace
Tab.Web
{
[
ServiceContract(Namespace = "")]
[
AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
[
OperationContract]
public DataTable GetActivePatient(string Role, int RoleIdentity)
{
Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbCommand = db.GetStoredProcCommand("[GetActivePatients_ByRole]");
db.AddInParameter(dbCommand,
"@Role", DbType.AnsiString, Role);
db.AddInParameter(dbCommand,
"@RoleIDentity", DbType.Int32, RoleIdentity);
try
{
DataSet dataSet = db.ExecuteDataSet(dbCommand);
return dataSet.Tables[0];
}
catch (Exception)
{
return null;
}
}
using this wcf i m getting patient list which is stored in my Database.
On page.xaml.cs i have used this service to fill datagrid i.e Acptlist
private
void AcPtlist_Loaded(object sender, RoutedEventArgs e)
{
Tab.ServiceReference1.
Service1Client WebServices = new Tab.ServiceReference1.Service1Client();
WebServices.GetActivePatientCompleted +=
new EventHandler<Tab.ServiceReference1.GetActivePatientCompletedEventArgs>(WebServices_GetActivePatients);
WebServices.GetActivePatientAsync(
"Hospitalist", 3);
}
public void WebServices_GetActivePatients(object sender, Tab.ServiceReference1.GetActivePatientCompletedEventArgs e)
{
AcPtlist.ItemsSource = e.Result;
}
but it gives error that Error 1 Cannot implicitly convert type 'Tab.ServiceReference1.GetActivePatientResponseGetActivePatientResult' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)
can anyone help me.
Thank u
Sudhir
Wednesday, June 2, 2010 8:13 AM
Answers
-
Hi,
There is no direct way you can bind datatable to datagrid in you silverlight application.
You will need to create some business objects to represent your data and return a list of those objects.
Thanks
Binze
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked as answer by Bin-ze Zhao Tuesday, June 8, 2010 5:45 AM
Monday, June 7, 2010 9:12 AM
All replies
-
Hi,
There is no direct way you can bind datatable to datagrid in you silverlight application.
You will need to create some business objects to represent your data and return a list of those objects.
Thanks
Binze
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked as answer by Bin-ze Zhao Tuesday, June 8, 2010 5:45 AM
Monday, June 7, 2010 9:12 AM -
Hi you can refer following links for diffrent ways of binding data to gridview in silverlight
Regards,
Sathisha N M
Sathisha N.M Senior Software Engineer- Proposed as answer by Sathisha N.M Wednesday, February 1, 2012 6:41 AM
Wednesday, February 1, 2012 6:41 AM