c# - Can't find HTML control in codebehind -
i have div (id=main), contains 15 html select controls within , ids ddl1, ddl2, ddl3, ... , on.
now want dynamically select or assign indexes xml file, wrote code.
private void readxml(string spath) { xmldocument doc = new xmldocument(); doc.load(spath); //doc.loadxml(spath); xmlnodelist xmlnodes = doc.selectnodes("/hedge/*"); (int i=1; <= 15; i++) { (main.findcontrol("ddl" + i) dropdownlist).selectedindex = int32.parse(xmlnodes[i].innertext); } }
but error occuring here...
object reference not set instance of object.
it's maybe because it's not able find controls (html select controls)... can tell me reason or solve problem?
there 2 thing may have went wrong. 1 obvious
(main.findcontrol("ddl" + i) dropdownlist).selectedindex = int32.parse(xmlnodes[i].innertext);
since not using asp.net dropdown list can not cast this. should be
(main.findcontrol("ddl" + i) htmlselect).selectedindex = int32.parse(xmlnodes[i].innertext);
another attribute runat="server"
needs there if suing html controls
, want access on c# page.
<select id="select1" runat="server"> <option value="1" selected="true"> item 1 </option> ..... </select>
c# asp.net xml
No comments:
Post a Comment