У меня есть веб-форма asp.net, которая содержит раскрывающееся меню formView, 3 и кнопку отправки. Выпадающие меню получают свои значения из базы данных.Получите значения из выпадающего меню, запустите запрос и добавьте значения в formview C#
Когда пользователь нажимает на значения кнопки отправки, из выпадающего меню следует запускать наш запрос и отображать результат в формеView. Этого не происходит.
Когда мы даем стандартные значения для других, мяса и овощей в 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" />
<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>
Любая помощь приветствуется!
Это не совсем ясно, что это проблема, которую вы испытываете. –
Отправьте свой точный вопрос, который вы испытываете с помощью этого кода. –
Я отредактировал мой вопрос, я надеюсь, что теперь это будет немного более ясно. Спасибо за ваши реакции ребята :) –