开发者

IEnumerable type cast

{
-- 
public static IEnumerable<Datarow> Codes(string topvalue)
    {

        DataTable itemCodes = new DataTable();

        itemCodes.Columns.Add("itemId");
        itemCodes.Columns.Add("itemCode");

        itemCodes.Rows.Add(0, firstCallingCode);
        DataTable Codes = GetAllItems().Tables[0];
        foreach (DataRow item in Codes.Rows)
        {
            if (item["ItemCode"] != DBNull.Value)
            {
                itemCodes.Rows.Add(item.Field<int?>("itemId"), item.Field<string>("itemCode"));
            }
        }
        return itemCodes.AsEnumerable();d
    }

how can i bind it to dropdownlist: i tried this

ddcodes.datasource = codes.getenumerable();开发者_如何学C
ddcodes.databind();

when i do this i get error about typecast. i can not solve it tried a lot please help. my method is actually this

public static IEnumerable"Datarow" Codes(string topvalue)

dont know why editor took that datarow off. bracket and datarow.


You just need to pass in the return value from the Codes method.

ddcodes.datasource = Codes();
ddcodes.databind();

You don't need to "get" an enumerable. The Codes method is already returning one.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜