首页 > 解决方案 > 根据其数据库表列值在 Silverlight 网站中显示值

问题描述

我有一个数据库表,其中有一个名为Status的列,“Status”列中的值将是 1 或 0 或 Null。我想要实现的是,如果值为 1 则应显示On,如果值为 0 则应显示Off,如果值为 null ,则应显示null。这是我到目前为止尝试过的一些片段,我无法弄清楚如何根据表列值显示结果。我附上了数据库的示例输出。请提供一些想法,在这种情况下可能对我有用
输出显示

#Accessing table value
public IQueryable<MSDS_VII> GetMSDS()
{
    return (
        from r in this._context.MSDS_VII
        orderby r.NO
        select r);
}

#Creating ria service
   public void GetMSDS(Action<CustomLoadOperation<MSDS_VII>> loadCompleted, object 
   userState = null, int pageSize = 20)
    {
        new CustomDataAdapter<MSDS_VII>(this.client, this.client.GetMSDSQuery(), this.client.MSDS_VIIs, pageSize, loadCompleted, userState);
    }

#View Model
public class MSDSStatusViewModel : BaseViewModel
{

    [ImportingConstructor]
    public MSDSStatusViewModel(IWindowManager windowManager, IEventAggregator eventAggregator, DomainServiceClient service)
        : base()
    {
        this.windowManager = windowManager;
        this.service = service;
        this.eventAggregator = eventAggregator;
        this.DisplayName = "MSDS VII Status";
    }

    public DomainCollectionView<MSDS_VII> msdsList;
   
    public DomainCollectionView<MSDS_VII> MSDSList
    {
        get
        {
            return this.msdsList;
        }
        set
        {
            this.msdsList = value;
            this.NotifyOfPropertyChange(() => MSDSList);
        }
    }


    public override void GetData()
    {
        this.service.GetMSDS(this.OnGeneralItemsLoadCompleted<MSDS_VII>);
    }

    public override void OnGeneralItemsLoadCompleted<TEntity>(CustomLoadOperation<TEntity> result)
    {
        base.OnGeneralItemsLoadCompleted(result);
        if (result.Result.IsComplete)
        {
            if (typeof(TEntity).Equals(typeof(MSDS_VII)))
            {
                MSDSList = result.CollectionView as DomainCollectionView<MSDS_VII>;                      
            }
        }
    }

#View xaml code
<c1:C1FlexGrid Grid.Row="1" ItemsSource="{Binding MSDSList}"  AutoGenerateColumns="False" HeadersVisibility="Column" GroupRowPosition="BelowData" MaxColumnWidth="500" c1:LicenseMode.Evaluation="True">
        <c1:C1FlexGrid.Columns>
           <c1:Column Binding="{Binding NO}" Header="NO."Width="70" />
           <c1:Column Binding="{Binding ITEM}" Header="Item" Width="400"  />
           <c1:Column Binding="{Binding STATUS}" Header="Status" Width="130" />
        </c1:C1FlexGrid.Columns>
 </c1:C1FlexGrid>

标签: c#mvvmwcf-ria-servicessilverlight-5.0

解决方案


您需要创建一个自定义转换器来将值转换为适合控件的值,反之亦然。网上有很多例子..我在快速搜索后找到了这个应该可以帮助你的例子.. IValueConvertor


推荐阅读