开发者

How is empty string collection any different from other empty collections, which don’t cause an exception

开发者 https://www.devze.com 2022-12-13 06:59 出处:网络
If ObjectDataSource.SelectMethod = A and if A() returns a single object of type O, then this object is wrapped in a one element IEnumerable collection and returned by the ODS.Select method

If ObjectDataSource.SelectMethod = A and if A() returns a single object of type O, then this object is wrapped in a one element IEnumerable collection and returned by the ODS.Select method

Thus, assuming ODS.SelectMethod points to method A(), then if A() returns a null , when called by ODS, this null is ( I assume ) wrapped into one element IEnumerable collection and no exception is thrown. Similarly, if ODS.SelectMethod points to method B(), which returns a list of objects, and if B() returns an empty collection when called by ODS, then no exception is thrown.

But if a method would instead return ( when called by ODS.Select ) an empty string collection (string[]), then I’d get exception “The data source for GridView did not have any properties or attributes from which to generate columns”. How is empty string collection any different from other empty collections, which don’t cause an e开发者_如何学JAVAxception?

Thanx


If your GridView has AutoGenerateColumns set to true, it requires a sequence of objects which have bindable members, like a DataRow. The column autogenerator inspects the signature of the sequence passed in and knows how to handle a few various cases, such as a DataRow which has a collection of columns which can be inferred into a list of columns on the GridView control. A string has no such properties. Set AutoGenerateColumns to false, and define your own column, like so:

<Columns>
    <asp:TemplateField>
        <ItemTemplate><%# Container.DataItem %></ItemTemplate>
    </asp:TemplateField>
</Columns>

A string is pretty limited as a datasource for a GridView - unless you plan to eval properties about the string like it's Length, you can really just print the string itself (DataItem).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号