c# - asp.net - problems getting dropdownlist -
i using code behind function bind dropdownlist dynamically, when user changes dropdownlist , submit purchase, selectedvalue empty.
i have tried both ddl.selecteditem.tostring(); , ddl.selectedvalue.tostring(); none work. these 2 code behind functions below, can't seem use void methods instead of function needs returning value , parameter, there anyway use void methods without parameters? advice appreciated.
thanks.
<%# formattedsize((string)eval("size")) %> <%# formattedgetsize((string)eval("size")) %> inline:
<asp:dropdownlist id="dropdownlist1" runat="server" ondatabinding='<%# formattedsize((string)eval("size")) %>'></asp:dropdownlist> <a href='addtocart.aspx?categoryid=<%# eval("categoryid") %>&&productid=<%# eval("productid" ) %>&&size=<%# formattedgetsize((string)eval("size")) %>' style="border: 0 none white;"> code behind:
protected string formattedsize(string size) { if (size.contains("s")) { dropdownlist ddl = (dropdownlist)formview_product.row.cells[0].findcontrol("dropdownlist1"); ddl.items.add("s"); } if (size.contains("m")) { dropdownlist ddl = (dropdownlist)formview_product.row.cells[0].findcontrol("dropdownlist1"); ddl.items.add("m"); } if (size.contains("f")) { dropdownlist ddl = (dropdownlist)formview_product.row.cells[0].findcontrol("dropdownlist1"); ddl.items.add("freesize"); } return null; } protected string formattedgetsize(string size) { dropdownlist ddl = (dropdownlist)formview_product.row.cells[0].findcontrol("dropdownlist1"); string selectedsize = ddl.selecteditem.tostring(); return selectedsize; }
the reason why doesn't work because.. "you're doing wrong". you're expecting <a href=.. change based on user interaction instead generated when user receives page. if want link change based on dropdown, you'd have have either:
- a postback on dropdown selection, link change...
- you change
hrefjavascript attaching event on dropdown selection
Comments
Post a Comment