Just RUN

A scientist builds in order to learn; an engineer learns in order to build.

DataGrid不能绑定Field?

也许又是后之后觉,事情是这个样子地。

昨天看了看DNN,弄了个google search,今天,想把它完成,一定要用google的WSDL了,用wsdl.exe生成了一个C#代码,其中result里有一个ResultElement的数组,就要用datagrid绑它,呵呵,可以免去写分页的麻烦何乐而不为呢?

于是有了以下代码

                GoogleSearchService service = new GoogleSearchService();

                GoogleSearchResult result 
=  service.doGoogleSearch (ConfigurationSettings.AppSettings["GoogleKey"],
                    
this.queryTextBox.Text,
                    
0,
                    
10,
                    
false,
                    
"",
                    
false,
                    
"",
                    
"UTF-8",
                    
"UTF-8");

                
this.resultList.DataSource = result.resultElements;
                
this.resultList.DataBind();


绑定写成这样<%# DataBinder.Eval(Container.DataItem,"summary") %>

summary就是ResultElement的一个Field,怎么弄也弄不过去,无奈新建了一个工程试试该怎么绑

            this.resultList.DataSource = new TheElement[]{
                                                             
new TheElement(),
                                                             
new TheElement(),
                                                             
new TheElement(),
                                                             
new TheElement(),
                                                             
new TheElement(),
                                                             
new TheElement()
                                                         }
;
            
this.resultList.DataBind();

当TheElement类的定义是这样的时候,异常。

    public class TheElement
    
{
        
public string Hello = "hello";
    }

当TheElement类的定义改成这样的时候,OK。

    public class TheElement
    
{
        
public string Hello
        
{
            
get
            
{
                
return "Hello";
            }

        }

    }


搞不懂,为什么不让绑Field

posted on 2004-11-19 12:07    阅读(919)  评论(0编辑  收藏  举报

导航