asp.net - how to create master detail combobox in C#? -


i have excel sheet test.xlsx, 2 sheets within

sheet name : product1 has following data :

id  parentid    title 1   0           p1_1 2   0           p1_2 

sheet name : product2 has following data :

id  parentid    title 1   1           p2_1 2   1           p2_2 3   1           p2_3 4   1           p2_4 5   2           p2_5 6   2           p2_6 

calling both sheets in windowsformsapplication in asp net ( c# ) :

oledbconnection conn = new oledbconnection(); conn.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=d:\test.xlsx" + @";extended properties=""excel 12.0 xml;hdr=yes;imex=1;importmixedtypes=text;typeguessrows=0""";  /////////////////////////////////////////////////////  oledbcommand command1 = new oledbcommand ( "select id ,parentid ,title " + " [product1$]", conn ); dataset ds1 = new dataset(); oledbdataadapter adaptor1 = new oledbdataadapter(command1); adaptor1.fill(ds1); product1.datasource = ds1.tables[0]; product1.valuemember = "id"; product1.displaymember = "title";  /////////////////////////////////////////////////////  oledbcommand command2 = new oledbcommand ( "select id  ,parentid ,title " + " [product2$] " , conn ); dataset ds2 = new dataset(); oledbdataadapter adaptor2 = new oledbdataadapter(command2); adaptor2.fill(ds2); product2.datasource = ds2.tables[0]; product2.valuemember = "id"; product2.displaymember = "title"; 

i need know how create master-detail ( parent - child ) relation in both combo-box when first combo box value change , 2nd combo-box value reflect changed parentid field ..

you can firing event when item selected combobox1 selecting current selected value. based on selected value data sheet2 , fill second combobox.

<asp:listbox id="product1" onselectedindexchanged="product1_selectedindexchanged" runat="server" autopostback="true"></asp:listbox> 

cs code

int id = 0; int.tryparse(product1.selectedvalue, out id); 

now based on id data sheet2

oledbcommand command2 = new oledbcommand ( "select id  ,parentid ,title " + "from [product2$] parentid=@parentid" , conn ); command2.parameters.addwithvalue("@parentid", id); 

and rest of code biniding same.