2013-07-29 2 views
0

두 개의 드롭 다운 목록이 있고 두 번째 드롭 다운 목록은 첫 번째로 선택한 값을 기반으로 채워집니다. 이것은 두 번째 드롭 다운 목록이 채워진 방법 이었지만 첫 번째 선택 항목을 기반으로 작성하지 않았기 때문에 채우기 방법을 변경하게되었습니다.다른 드롭 다운 목록을 기반으로 드롭 다운 목록을 채우는 중 오류가 발생했습니다.

전 :

<asp:DropDownList ID="RootDropDown" runat="server" AutoPostBack="True" DataSourceID="FirstChild" DataTextField="DisplayName" DataValueField="ID"></asp:DropDownList> 
     <asp:SqlDataSource ID="FirstChild" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnection %>" SelectCommand="SELECT e.DisplayName, e.ID , e.GUID 
FROM SomeTable e 
INNER JOIN TabletoTableMap em 
ON e.ID = em.OtherTableID 
WHERE em.SomeTableID = 9"+ ></asp:SqlDataSource> 

후 :

<asp:DropDownList ID="RootDropDown" runat="server" AutoPostBack="True" DataSourceID="FirstChild" DataTextField="DisplayName" DataValueField="ID" OnSelectedIndexChanged="Child"></asp:DropDownList> 

아동 방법 :

protected void Child(object sender, EventArgs e) 
    { 
     String strConnection = "Data Source=.;Initial Catalog=ALE;Integrated Security=True"; 
     int RootID = Convert.ToInt32(CourseDropDown.SelectedValue); 
     System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strConnection); 
     con.Open(); 
     System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT e.DisplayName, e.ID , e.GUID FROM SomeTable e INNER JOIN TabletoTableMap em ON e.ID = em.OtherTableID WHERE em.SomeTableID="+RootID, con); 
     System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd); 
     System.Data.DataSet ds = new System.Data.DataSet(); 
     da.Fill(ds); 
     con.Close(); 
     RootElementDropDown.DataSourceID = "FirstChild"; 
     RootElementDropDown.DataTextField = "DisplayName"; 
     RootElementDropDown.DataValueField = "ID"; 
     RootElementDropDown.DataBind(); 
    } 

오류 :

The DataSourceID of 'RootDropDown' must be the ID of a control of type IDataSource. A control with ID 'FirstChild' could not be found. 
+0

친절하게 답변을 수락하십시오 ,,,, !!!! – Aravind

답변

0

설정하려고 시도하십시오

DataMember as what you want 
+0

어떤 부분을 의미합니까? – Masriyah

+0

이미 DataValuefield id를 설정했습니다. 첫 번째 dropdownlist를 selectedindexchanged했을 때 두 번째 드롭 다운 목록을 채우기위한 메소드를 추가 한 다음 이전에 선택한 항목을 datamember 속성으로 설정하여 항목을 선택하고 채우려는 항목을 얻습니다 – Aravind

관련 문제