c# - Use a FOR loop to return SelectedValue of DropDownList -


i've been spending lot of time searching solution seems simple thing.

the following returns "object reference not set instance of object." error. put code on separate blank page troubleshooting. ideas?

asp.net:

<div>     <asp:dropdownlist id="choosepattern1" clientidmode="static" runat="server" cssclass="dropformat"         autopostback="true" onselectedindexchanged="getimage">         <asp:listitem>1</asp:listitem>         <asp:listitem>2</asp:listitem>         <asp:listitem>3</asp:listitem>     </asp:dropdownlist>     <asp:dropdownlist id="choosepattern2" clientidmode="static" runat="server" cssclass="dropformat"         autopostback="true" onselectedindexchanged="getimage">         <asp:listitem>1</asp:listitem>         <asp:listitem>2</asp:listitem>         <asp:listitem>3</asp:listitem>     </asp:dropdownlist> </div> 

c# codebehind:

protected void getimage(object sender, eventargs e) {     (int intcounter = 1; intcounter <= 8; intcounter++)     {         string mypattern = "choosepattern" + convert.tostring(intcounter);          dropdownlist ddl = page.findcontrol(mypattern) dropdownlist;         response.write(ddl.selectedvalue);     } } 

that error message called "null reference exception". means you're trying access property object, object null.

in case, ddl problem. if it's not found page.findcontrol (or if returned object not dropdownlist), value stored null. therefore, accessing selectedvalue cause exception.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -