0

我有一个asp.net webform,其中包含一个formView、3 个下拉菜单和一个提交按钮。下拉菜单从数据库中获取它们的值。

当用户单击下拉菜单中的提交按钮值时,应该运行我们的查询并在 formView 中显示结果。这没有发生。

当我们在 callSelectProduct() 中为其他肉类和蔬菜提供标准值时,我们可以在表单视图中看到正确的输出,但这是在页面加载时。

这是提交按钮的点击方法:

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);
    }

这是 callSelectProduct():Debug.WriteLine 会在调试控制台中返回正确的值,但随后由于单击提交按钮而重新加载页面,然后 Debug.WriteLine 会返回 0 0 0。我认为这就是为什么我在 FormView 中看不到任何内容的原因。因为 0 0 0 的组合不会返回任何东西。

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 is class 1 Other  " + other + " Vegetable " + vegetables + " Meat " + meat);
            DataAccess.SouthWindTableAdapters.SelectRecipesFromIngredientsTableAdapter tableAdaptertest = new DataAccess.SouthWindTableAdapters.SelectRecipesFromIngredientsTableAdapter();
            return tableAdaptertest.GetData(other, meat, vegetables);


        }

这是我们的网络表单:

 <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" />
            &nbsp;<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" />
            &nbsp;<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>

欢迎任何帮助!

4

1 回答 1

0

您是否在页面加载事件内部的下拉绑定方法中使用 !IsPostBack ?

为了

void page-load()
{
if(!IsPostBack)
{
//Call all dropdownlist binding method  
}

}
于 2013-05-19T07:15:20.657 回答