asp.net - Get values from dropdown menu's, run query and add values to formview c# -
i have asp.net webform contains formview, 3 dropdown menus , submit button. dropdown menus values database.
when user clicks submit button values dropdown menus should run through our query , display outcome in formview. not happening.
when give standard values other, meat , vegetables in callselectproduct() can see correct output in form view, on page load.
this click method submit button:
protected void getrecipe(object sender, eventargs e) { string ddlother = dropdownother.selectedvalue; string ddlvegetables = dropdownvegetables.selectedvalue; string ddlmeat = dropdownmeat.selectedvalue; int ddlintother = int.parse(ddlother); int ddlintvegetables = int.parse(ddlvegetables); int ddlintmeat = int.parse(ddlmeat); business.class1.callselectproduct(ddlintother, ddlintmeat, ddlintvegetables); }
this callselectproduct(): debug.writeline gives values in debug console, page reloads because of submit button click , debug.writeline gives 0 0 0 back. think that's why don't see in formview. because combination of 0 0 0 not return anything.
public static void callselectproduct(int other, int meat, int vegetables) { selectproduct(other, meat, vegetables); } [system.componentmodel.dataobjectmethod(system.componentmodel.dataobjectmethodtype.select)] public static data.southwind.selectrecipesfromingredientsdatatable selectproduct(int otherget, int meatget, int vegetablesget) { int other = otherget; int meat = meatget; int vegetables = vegetablesget; system.diagnostics.debug.writeline("this class 1 other " + other + " vegetable " + vegetables + " meat " + meat); dataaccess.southwindtableadapters.selectrecipesfromingredientstableadapter tableadaptertest = new dataaccess.southwindtableadapters.selectrecipesfromingredientstableadapter(); return tableadaptertest.getdata(other, meat, vegetables); }
this our webform:
<form id="form1" runat="server"> <div> <asp:formview id="recipeformview" runat="server" allowpaging="true" datasourceid="objectdatasource1"> <edititemtemplate> recipename: <asp:textbox id="recipenametextbox" runat="server" text='<%# bind("recipename") %>' /> <br /> <asp:linkbutton id="updatebutton" runat="server" causesvalidation="true" commandname="update" text="update" /> <asp:linkbutton id="updatecancelbutton" runat="server" causesvalidation="false" commandname="cancel" text="cancel" /> </edititemtemplate> <insertitemtemplate> recipename: <asp:textbox id="recipenametextbox" runat="server" text='<%# bind("recipename") %>' /> <br /> <asp:linkbutton id="insertbutton" runat="server" causesvalidation="true" commandname="insert" text="insert" /> <asp:linkbutton id="insertcancelbutton" runat="server" causesvalidation="false" commandname="cancel" text="cancel" /> </insertitemtemplate> <itemtemplate> recipename: <asp:label id="recipenamelabel" runat="server" text='<%# bind("recipename") %>' /> <br /> </itemtemplate> </asp:formview> <asp:objectdatasource id="objectdatasource1" runat="server" oldvaluesparameterformatstring="original_{0}" selectmethod="selectproduct" typename="business.class1"> <selectparameters> <asp:parameter name="otherget" type="int32" /> <asp:parameter name="meatget" type="int32" /> <asp:parameter name="vegetablesget" type="int32" /> </selectparameters> </asp:objectdatasource> <asp:dropdownlist id="dropdownother" runat="server" datasourceid="objectdatasource2" datatextfield="ingredientname" datavaluefield="ingredientid"> </asp:dropdownlist> <asp:dropdownlist id="dropdownvegetables" runat="server" datasourceid="selectvegetables" datatextfield="ingredientname" datavaluefield="ingredientid" height="16px"> </asp:dropdownlist> <asp:dropdownlist id="dropdownmeat" runat="server" datasourceid="selectmeat" datatextfield="ingredientname" datavaluefield="ingredientid"> </asp:dropdownlist> <asp:objectdatasource id="selectmeat" runat="server" oldvaluesparameterformatstring="original_{0}" selectmethod="selectmeat" typename="business.class1"></asp:objectdatasource> <asp:objectdatasource id="selectvegetables" runat="server" oldvaluesparameterformatstring="original_{0}" selectmethod="selectvegetables" typename="business.class1"></asp:objectdatasource> <asp:objectdatasource id="objectdatasource2" runat="server" oldvaluesparameterformatstring="original_{0}" selectmethod="selectother" typename="business.class1"></asp:objectdatasource> <asp:button id="button1" runat="server" onclick="getrecipe" text="button" usesubmitbehavior="false" /> <br /> </div> </form>
any welcome!
are use !ispostback in outer of dropdown binding method in inside of pageload event ?
for
void page-load() { if(!ispostback) { //call dropdownlist binding method } }
Comments
Post a Comment