繁体   English   中英

如何使用WCF在ASP.NET C#中显示一行数据网格

[英]How to display one row of data grid in ASP.NET c# using WCF

我正在使用WCF在Silverlight应用程序中工作。 我想在数据网格中显示数据库中的特定行。

我发现e.result但是这将显示数据库的全部内容。

下面是我的代码:

public TrainingBatchesUsersResults(int TraineeID)//, int TrainingProgramID, int >ReadyContainerID, int TrainingBatch, int ReadyContainerItemID)
{
     InitializeComponent();
     XraySimulatorWCFServices.XraySimulatorServiceClient XrayClient =new XraySimulatorWCFServices.XraySimulatorServiceClient();

     XrayClient.GetTrainingBatchesUsersResultsCompleted += new EventHandler<
     XraySimulatorWCFServices.GetTrainingBatchesUsersResultsCompletedEventArgs>(DisplayTrainingBatchesUsersResults);

     XrayClient.GetTrainingBatchesUsersResultsAsync(TraineeID);

     LayoutRoot.UpdateLayout();
}

private void DisplayTrainingBatchesUsersResults(object sender, XraySimulatorWCFServices.GetTrainingBatchesUsersResultsCompletedEventArgs e)
{
       dgvResult.ItemsSource = e.Result;
     dgvResult.Visibility = System.Windows.Visibility.Visible;
}

只需将ItemsSource设置为要显示的单行,而不是整个结果集合即可。 例如dgvResult.ItemsSource=e.Result.FirstOrDefault(x=>x.Id==theIdYouWantToShow)

但是,您真正想要的是在整个链上进行此操作,以便仅返回所需的单行,而不是返回整个表并减少客户端上的设置。 您的呼叫XrayClient.GetTrainingBatchesUsersResultsAsync(TraineeID); 大概是在返回所有行,为什么不拥有一个只返回您感兴趣的单个结果的新方法呢?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM