开发者

Ienumerable<KeyValuePair<T, string>> as a datasource . how to?

I have a generic method that returns

IEnumerable<KeyValuePair<T, string>> 

but i expect the T to be an integer. How can i bind this to combo box in an asp.net web form application?

Currently i get an exepction when i bind the result to my combobox. my method is be

public static IEnumerable<KeyValuePair<T, string>> GetData<T>(IEnumerable<global::Dev.DAL.pets> st, Func<global::Dev.DAL.pets, T> getDat开发者_运维知识库a)
    {
        var filtered = st.Select(a => new  { Id = getData(a), Code = Convert.ToInt32(getData(a)).ConvertToCode() });
        foreach(var v in filtered )
            yield return new KeyValuePair<T, string>(v.Id, v.Code );



    }


I assume your markup (or code) is setting the DataTextField/DataValueField properties of the DropDownList incorrectly.

Try setting the DataTextField to "Value" and the DataValueField to "Key".

<asp:DropDownList ... DataTextField="Value" DataValueField="Key" ...
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜