dropdownlist 绑定

1、dpdDeptProfessional.DataSource =dt.DefaultView;
     dpdDeptProfessional.DataValueField="PID";
     dpdDeptProfessional.DataTextField="PName";
     dpdDeptProfessional.DataBind();

 

2、 foreach (DataRow row in dt.Rows)
      {
                 this.dpdDeptProfessional.Items.Add(new ListItem(row["subjectName"].ToString(), row["subjectID"].ToString()));
      }

 

ListItem item = this.dpdDeptProfessional.Items.FindByText(row["PName"].ToString());

if (item != null)
{
        item.Selected = true;
}

你可能感兴趣的:(dropdownlist 绑定)