using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class _Default : System.Web.UI.Page { SoundLakeDataClassesDataContext sldc = new SoundLakeDataClassesDataContext(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var doctor = from d in sldc.AbtDoctors select new { d.LastName, d.AbtDoctorId }; DropDownList1.DataSource = doctor; DropDownList1.DataTextField = "LastName"; DropDownList1.DataValueField = "AbtDoctorID"; DropDownList1.DataBind(); DropDownList1.Items.Insert(0,"Choose a Doctor"); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownList1.SelectedIndex != 0) { var patient = from p in sldc.AbtPatients join d in sldc.AbtDoctorPatients on p.AbtPatientId equals d.AbtPatientId where d.AbtDoctorId == int.Parse(DropDownList1.SelectedValue.ToString()) select new { p.FirstName, p.LastName, p.PatientAddress, p.Phone }; GridView1.DataSource = patient; GridView1.DataBind(); } } }