如何使用Generic List绑定下拉列表 [英] How to bind dropdown using Generic List

查看:116
本文介绍了如何使用Generic List绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用户控件,其中有dropdownlist。为了绑定下拉列表,我已将Generic List对象传递给方法。



I have created a user control where in there is dropdownlist. To bind dropdownlist I have passed Generic List object to a method.

public void BindDropDownList<T>(List<T> data, string val, string txt)
        {
            foreach (var v in data)
            {

            }
        }







并将此方法称为如下。






and called this method like below.

msc_accounthead.BindDropDownList<AccountHead>(acc_list, "ahmID", "ahmHead");





供参考点击这里



我如何访问属性(以绿色突出显示)来绑定drpdownlist?



for reference Click Here

How can I access properties(highlighted by green) to bind a drpdownlist?

推荐答案

我认为你不想循环。下面应该可以工作。

I don't think you ned to loop. Below should work.
ddlDropdownId.DataSource = data;
ddlDropdownId.DataTextField = txt;
ddlDropdownId.DataValueField = val;
ddlDropdownId.DataBind();


这篇关于如何使用Generic List绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆