如何绑定列表< MyClass的>与gridview的数据? [英] How to Bind List<myclass> data with gridview?

查看:104
本文介绍了如何绑定列表< MyClass的>与gridview的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href="http://stackoverflow.com/questions/934479/how-to-adjust-is-a-type-but-is-used-like-a-variable">请看看我的web服务codeS返回类型列表

我从与listformat列表Web服务数据;还创建低于GridView和返回列表的GridView datasource.Bur eror发生:

名为名称字段或属性没有被选定的数据源上找到。

 
        <栏目>
        的
        的
        的
        
          

  wstest WS =新wstest();
            GridView1.DataSource = ws.GetList(); ;
            GridView1.DataBind();  

解决方案

检查清单您生成的内容。如果你没有这样的获取输出,当你调用一个域名为名称的GetList()那么这将打破,因为在GridView正在寻找它,它不存在绑定到

您可能必须贴上一些code为我们不过验证。

修改:根据您所创建的类的链路上,似乎你需要确认你的财产name是用于在各个领域的适当的资本。 C#是区分大小写的,这样很可能就是它被揭去。请确保你的其他属性也是如此。

编辑2 :还应当指出的是,混乱可能是一个事实,即你的私有成员都是小写的,而你的财产予以资本化。你的GridView将被绑定到公共属性,所以这就是为什么你要确保在GridView正在寻找在资本属性名,姓,等等。

Look please my web service codes return type List

i get data from web service with listformat List; also created a gridview below and return list to gridview datasource.Bur eror occurs:

A field or property with the name 'name' was not found on the selected data source.

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
        <Columns>
        <asp:BoundField HeaderText="Ad" DataField="name" />
        <asp:BoundField HeaderText="SoyAd" DataField="surname" />
        <asp:BoundField HeaderText="Numara" DataField="number" />
        </Columns>
        </asp:GridView>

 wstest ws = new wstest();
            GridView1.DataSource = ws.GetList(); ;
            GridView1.DataBind();

解决方案

Check the contents of your list that you generate. If you do not have a field called name that gets output when you call GetList() then it's going to break because the GridView is looking for it and it's not there to bind to.

You may have to paste some more code for us to verify that, however.

Edit: based on your link of the class you created, it seems that you need to verify that your property "Name" is used with the proper capitalization in all areas. C# is case sensitive so that is most likely why it is being thrown off. Make sure for your other properties as well.

Edit 2: It should also be noted that the confusion may be from the fact that your private members are all lowercase, while your properties are capitalized. Your GridView is going to be binding to the public properties, so that is why you want to make sure the Gridview is looking at the capitalized properties "Name", "SurName", etc.

这篇关于如何绑定列表&LT; MyClass的&GT;与gridview的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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