62,046
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<Department> list = new List<Department> { new Department(1, "a"), new Department(2, "b"), new Department(3, "c") };
DropDownList1.DataSource = list;//这里只是测试方便,换成你的绑定数据源
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "ID";
DropDownList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ListItem item = DropDownList1.SelectedItem;
Department depart = new Department();
depart.Id = Convert.ToInt32(item.Value);
depart.Name = item.Text;
Response.Write(depart.Id + "==" + depart.Name);
}
protected void topicbind()
{
string sql = "select [ID],[P_title] from [Projectlist] order by [ID] desc";
DataTable dt = SqlHelper.getdatatable(sql);
DataRow[] drs = dt.Select("", "ID");
foreach (DataRow dr in drs)
{
string id = dr["ID"].ToString();
string p_title = dr["P_title"].ToString();
list.Items.Add(new ListItem(p_title, id));
}
list.DataBind();
}