views:

1344

answers:

2

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();
A: 

This line

<asp:BoundField HeaderText="Ad" DataField="name" />

is saying to get a proprty value from each item in teh list, and bind it to this column within the grid. It would seem that the item within the list don't have a property "Name"

Tetraneutron
Look please: http://stackoverflow.com/questions/934479/how-to-adjust-is-a-type-but-is-used-like-a-variable
Phsika
C# is case sensitive, make it<asp:BoundField HeaderText="Ad" DataField="Name" />and it should work
Tetraneutron
+1  A: 

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.

TheTXI
Look please: http://stackoverflow.com/questions/934479/how-to-adjust-is-a-type-but-is-used-like-a-variable
Phsika