将数据绑定到Silverlight DataGrid时出现问题 [英] Problem binding data to Silverlight DataGrid

查看:64
本文介绍了将数据绑定到Silverlight DataGrid时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发一个使用WCF服务与数据库进行交互的Silverlight Web应用程序.我将数组列表从DAL层返回到Xaml.cs,但无法将其绑定到Datagrid.
我的代码部分如下:

Hi
I am developing a Silverlight web application that uses WCF services to interact with database. I return a arraylist from DAL layer to Xaml.cs but could not bind it to Datagrid.
My Code section is as follows:

if (e.Error != null)
{
    //Error Condition
}
else
{
    dataGrid1.ItemsSource = e.Result;
}



如果我使用datagrid1.ItemSource = e.Result; ..
,则数据未绑定 请在这方面提出您的宝贵建议.

谢谢
Naresh.



The data is not getting binded if I use datagrid1.ItemSource = e.Result;..
Please give your valuable suggestions in this regard.

Thanks
Naresh.

推荐答案

e.result包含什么?是收藏吗?

注意:Silverlight 不支持数组列表,您需要使用ObservableCollection .

任何IEnumerable都可用作项源,而不仅仅是ObservableCollection.
What does e.result contain? Is it a collection?

Note: Arraylists are not supported in Silverlight and you need to use an ObservableCollection.

Any IEnumerable can be used as an itemssource, not just ObservableCollection.


您需要启用AutoGenerateColumns
You need to Either enable AutoGenerateColumns
dataGrid1.AutoGenerateColumns = true;



或者,您可以添加列并指定绑定



OR you can Add column and specify binding

<sdk:DataGrid AutoGenerateColumns="False" Height="185" HorizontalAlignment="Left" Margin="33,66,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="325">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="Test" Width="Auto" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>


这篇关于将数据绑定到Silverlight DataGrid时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆