我需要从具有onSelected属性和databind的sqlserver中填充下拉列表

时间:2019-07-31 11:18:09

标签: c# asp.net forms web

我已经在sql服务器数据库中插入了数据,现在我试图更新这些记录,以便可以进行更改,但是当我使用datatable函数填充文本框时,它可以正常工作,但不会填充所选的“程序,组和类”下拉列表”中选择的数据库值或选定的项目。

protected void campus_SelectedIndexChanged(object sender, EventArgs e)
       {
           program.DataSource = dm.getData("SELECT DISTINCT cpCampusCode, cpCamName, cpProgramCode, cpProgName  From   CampusPrograms Where cpCampusCode = '" + campus.SelectedValue + "'");
           program.DataTextField = "cpProgName";
           program.DataValueField = "cpProgramCode";
           program.DataBind();
           program.Items.Insert(0, new ListItem("Select Program", "0"));
       }

protected void program_SelectedIndexChanged(object sender, EventArgs e)
       {
           Group.DataSource = dm.getData("Select DISTINCT a.ProgramCode, a.ProgramName, a.GroupCode AS GroupCode, a.GroupName AS GroupName from ProgramGroup a Inner Join CampusPrograms b ON b.cpProgramCode=a.ProgramCode Where b.cpProgramCode =  '" + program.SelectedValue + "' Order by GroupName ASC");
           Group.DataTextField = "GroupName";
           Group.DataValueField = "GroupCode";
           Group.DataBind();
           Group.Items.Insert(0, new ListItem("Select Group", "0"));
       }

protected void stdid_SelectedIndexChanged(object sender, EventArgs e)
       {
           Button1.Enabled = false;
           UpdtBtn.Enabled = true;
           DataTable dt = dm.getData("select * from StudentInquiry si inner join CampusPrograms a on si.iProgramCode=a.cpProgramCode  Where si.inqID='" + stdid.SelectedValue + "'");
           foreach (DataRow dr in dt.Rows)
           {
               doi.Text = "" + dr["iDateOfInquiry"];
               campus.SelectedValue = "" + dr["iCamCode"];
               program.SelectedValue = "" + dr["iProgramCode"];
               Group.SelectedValue = "" + dr["iGroupCode"];
               Class.SelectedItem.Text = "" + dr["iClassCode"];


               stName.Text = "" + dr["iStName"];
               stCnic.Text = "" + dr["iCnic"];
               dob.Text = "" + dr["iDOB"];
               birthCity.SelectedItem.Text = "" + dr["iPlaceOfBirth"];
               sphone.Text = "" + dr["iPhoneNo"];
               smobile.Text = "" + dr["iMobileNo"];
               semail.Text = "" + dr["iEmailID"];
               saddress.Text = "" + dr["iAddress"];
               gender.SelectedItem.Text = "" + dr["iGender"];
               Religion.SelectedItem.Text = "" + dr["iReligion"];
               DropDownList2.SelectedItem.Text = "" + dr["iMaritalStatus"];
               Countries.SelectedItem.Text = "" + dr["iNationality"];
               ffname.Text = "" + dr["iFFName"];
               flname.Text = "" + dr["iFLName"];
               fmob.Text = "" + dr["iFMobile"];
               fnic.Text = "" + dr["iFCnic"];
               qua.SelectedItem.Text = "" + dr["iLastQualification"];
               lastins.Text = "" + dr["iLastInstitute"];
               pyear.SelectedItem.Text = "" + dr["iPassingYear"];
               Grade.Text = "" + dr["iGrade"];
               RadioButtonList1.SelectedValue = "" + dr["iSource"];
               remarks.Text = "" + dr["iRemarks"];
           }

       }

0 个答案:

没有答案