У меня есть gridview с его собственным sqlDataSource. В строке нижнего колонтитула у меня есть поле Insert, чтобы создать новую строку. Однако эта строка нижнего колонтитула довольно сложная, и я пытаюсь понять, как заставить ее работать.как заполнить выпадающий список на основе выбора другого dropdownlist в gridview
Что бы я хотел видеть, так это то, что пользователь выбирает имя OTypeName ddl. Основываясь на этом выборе, OSpecies ddl включен и заполняет значения на основе ODypeName ddl. То же самое можно сказать о OSpecies и OVariety.
Затем пользователь вводит свою собственную информацию в OAge, OYields, OPlantDate и OPlantFrom.
Остальные поля в нижнем колонтитуле являются метками, которые будут заполнены на основе окончательного выбора OVariety.
Кнопка Insert добавляет все эти столбцы в gridview.
Мне нужна помощь только с заполнением одного ddl на основе выбора ddl другого и как заполнить метку на основе выбора ddl.
Вот мой код в файле ASPX:
<%@ Page Title="" Language="C#" MasterPageFile="~/Permaculture.Master" AutoEventWireup="true" CodeBehind="OrchardMainWebForm.aspx.cs" Inherits="PermacultureOrganizer.OrchardMainWebForm" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server" >
<asp:GridView ID="gvOrchardData" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="OUserOrchardID" DataSourceID="dsOrchardDatabase" CellPadding="4" CellSpacing="4" ForeColor="#333333" GridLines="Vertical" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" ShowFooter="True" Font-Bold="False">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="OUserOrchardID" InsertVisible="False" SortExpression="OUserOrchardID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("OUserOrchardID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("OUserOrchardID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="lbInsert"
runat="server"
OnClick="lbInsert_Click" ForeColor="White">Insert</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OTypeName" SortExpression="OTypeName">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"
runat="server"
AutoPostBack="True"
DataSourceID="dsTypeName"
DataTextField="OrchardTypeName"
DataValueField="OrchardTypeID" >
</asp:DropDownList>
<asp:SqlDataSource ID="dsTypeName" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT * FROM [tblOrchardType]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("OTypeName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlTypeName"
runat="server"
AutoPostBack="True"
DataSourceID="dsTypeName"
DataTextField="OrchardTypeName"
DataValueField="OrchardTypeID"
>
</asp:DropDownList>
<asp:SqlDataSource ID="dsTypeName" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT * FROM [tblOrchardType]"></asp:SqlDataSource>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OSpecies" SortExpression="OSpecies">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2"
runat="server"
SelectedValue='<%# Bind("OSpecies") %>'
AutoPostBack="True"
DataSourceID="dsSpecies"
DataTextField="Species"
DataValueField="OrchardTypeID">
<asp:ListItem>Select Species</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsSpecies" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT [Species], [OrchardTypeID] FROM [tblOrchardItem]"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("OSpecies") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlSpecies"
runat="server"
AutoPostBack="True"
DataSourceID="dsSpecies"
DataTextField="Species"
DataValueField="OrchardTypeID"
>
<asp:ListItem>Select Species</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsSpecies" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT [Species], [OrchardTypeID] FROM [tblOrchardItem]">
</asp:SqlDataSource>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OVariety" SortExpression="OVariety">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList3"
runat="server"
AutoPostBack="True"
DataSourceID="dsVariety"
DataTextField="Variety"
DataValueField="OrchardTypeID">
</asp:DropDownList>
<asp:SqlDataSource ID="dsVariety" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT [Variety], [OrchardTypeID] FROM [tblOrchardItem]"></asp:SqlDataSource>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlVariety"
runat="server"
AutoPostBack="True"
DataSourceID="dsVariety"
DataTextField="Variety"
DataValueField="OrchardTypeID"
>
</asp:DropDownList>
<asp:SqlDataSource ID="dsVariety" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT [Variety], [OrchardTypeID] FROM [tblOrchardItem]"></asp:SqlDataSource>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("OVariety") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OAge" SortExpression="OAge">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("OAge") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtBxAge" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("OAge") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OYields" SortExpression="OYields">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("OYields") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtBxYields" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("OYields") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OPlantDate" SortExpression="OPlantDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("OPlantDate") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtBxPlantDate" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("OPlantDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OPlantFrom" SortExpression="OPlantFrom">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("OPlantFrom") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtBxPlantFrom" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("OPlantFrom") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OTreeSpacing" SortExpression="OTreeSpacing">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("OTreeSpacing") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTreeSpacing" runat="server"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("OTreeSpacing") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OFertilizingTimes" SortExpression="OFertilizingTimes">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("OFertilizingTimes") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblFertilizingTimes" runat="server"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("OFertilizingTimes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OWateringNeeds" SortExpression="OWateringNeeds">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("OWateringNeeds") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblWateringNeeds" runat="server"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("OWateringNeeds") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OPollination" SortExpression="OPollination">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("OPollination") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblPollination" runat="server"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("OPollination") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OFertilizer" SortExpression="OFertilizer">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("OFertilizer") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblFertilizer" runat="server"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("OFertilizer") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OPesticide" SortExpression="OPesticide">
<EditItemTemplate>
<asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("OPesticide") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="lblPesticide" runat="server"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label14" runat="server" Text='<%# Bind("OPesticide") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="Black" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<asp:SqlDataSource ID="dsOrchardDatabase" runat="server"
ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>"
SelectCommand="SELECT * FROM [tblUserOrchard]" DeleteCommand="DELETE FROM [tblUserOrchard] WHERE [OUserOrchardID] = @OUserOrchardID" InsertCommand="INSERT INTO [tblUserOrchard] ([OTypeName], [OSpecies], [OVariety], [OAge], [OYields], [OPlantDate], [OPlantFrom], [OTreeSpacing], [OFertilizingTimes], [OPruningTimes], [OWateringNeeds], [OPollination], [OFertilizer], [OPesticide]) VALUES (@OTypeName, @OSpecies, @OVariety, @OAge, @OYields, @OPlantDate, @OPlantFrom, @OTreeSpacing, @OFertilizingTimes, @OPruningTimes, @OWateringNeeds, @OPollination, @OFertilizer, @OPesticide)" UpdateCommand="UPDATE [tblUserOrchard] SET [OTypeName] = @OTypeName, [OSpecies] = @OSpecies, [OVariety] = @OVariety, [OAge] = @OAge, [OYields] = @OYields, [OPlantDate] = @OPlantDate, [OPlantFrom] = @OPlantFrom, [OTreeSpacing] = @OTreeSpacing, [OFertilizingTimes] = @OFertilizingTimes, [OPruningTimes] = @OPruningTimes, [OWateringNeeds] = @OWateringNeeds, [OPollination] = @OPollination, [OFertilizer] = @OFertilizer, [OPesticide] = @OPesticide WHERE [OUserOrchardID] = @OUserOrchardID">
<DeleteParameters>
<asp:Parameter Name="OUserOrchardID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="OTypeName" Type="String" />
<asp:Parameter Name="OSpecies" Type="String" />
<asp:Parameter Name="OVariety" Type="String" />
<asp:Parameter Name="OAge" Type="Int32" />
<asp:Parameter Name="OYields" Type="String" />
<asp:Parameter Name="OPlantDate" Type="String" />
<asp:Parameter Name="OPlantFrom" Type="String" />
<asp:Parameter Name="OTreeSpacing" Type="String" />
<asp:Parameter Name="OFertilizingTimes" Type="String" />
<asp:Parameter Name="OPruningTimes" Type="String" />
<asp:Parameter Name="OWateringNeeds" Type="String" />
<asp:Parameter Name="OPollination" Type="String" />
<asp:Parameter Name="OFertilizer" Type="String" />
<asp:Parameter Name="OPesticide" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="OTypeName" Type="String" />
<asp:Parameter Name="OSpecies" Type="String" />
<asp:Parameter Name="OVariety" Type="String" />
<asp:Parameter Name="OAge" Type="Int32" />
<asp:Parameter Name="OYields" Type="String" />
<asp:Parameter Name="OPlantDate" Type="String" />
<asp:Parameter Name="OPlantFrom" Type="String" />
<asp:Parameter Name="OTreeSpacing" Type="String" />
<asp:Parameter Name="OFertilizingTimes" Type="String" />
<asp:Parameter Name="OPruningTimes" Type="String" />
<asp:Parameter Name="OWateringNeeds" Type="String" />
<asp:Parameter Name="OPollination" Type="String" />
<asp:Parameter Name="OFertilizer" Type="String" />
<asp:Parameter Name="OPesticide" Type="String" />
<asp:Parameter Name="OUserOrchardID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsTypeName" runat="server" ConnectionString="<%$ ConnectionStrings:DB_9DE518_PermacultureConnectionString %>" SelectCommand="SELECT * FROM [tblOrchardType]"></asp:SqlDataSource>
</asp:Content>
Я не уверен, что поместить в файл aspx.cs, но вот то, что я до сих пор относительно кнопки Insert:
public void lbInsert_Click(object sender, EventArgs e)
{
dsOrchardDatabase.InsertParameters["OTypeName"].DefaultValue =
((DropDownList)gvOrchardData.FooterRow.FindControl("ddlTypeName")).SelectedItem.ToString();
dsOrchardDatabase.InsertParameters["OSpecies"].DefaultValue =
((DropDownList)gvOrchardData.FooterRow.FindControl("ddlSpecies")).SelectedItem.ToString();
dsOrchardDatabase.InsertParameters["OVariety"].DefaultValue =
((DropDownList)gvOrchardData.FooterRow.FindControl("ddlVariety")).SelectedItem.ToString();
dsOrchardDatabase.InsertParameters["OAge"].DefaultValue =
((TextBox)gvOrchardData.FooterRow.FindControl("txtBxAge")).Text;
dsOrchardDatabase.InsertParameters["OYields"].DefaultValue =
((TextBox)gvOrchardData.FooterRow.FindControl("txtBxYields")).Text;
dsOrchardDatabase.InsertParameters["OPlantDate"].DefaultValue =
((TextBox)gvOrchardData.FooterRow.FindControl("txtBxPlantDate")).Text;
dsOrchardDatabase.InsertParameters["OPlantFrom"].DefaultValue =
((TextBox)gvOrchardData.FooterRow.FindControl("txtBxPlantFrom")).Text;
dsOrchardDatabase.InsertParameters["OTreeSpacing"].DefaultValue =
((Label)gvOrchardData.FooterRow.FindControl("lblTreeSpacing")).Text;
dsOrchardDatabase.InsertParameters["OFertilizingTimes"].DefaultValue =
((Label)gvOrchardData.FooterRow.FindControl("lblFertilizingTimes")).Text;
dsOrchardDatabase.InsertParameters["OWateringNeeds"].DefaultValue =
((Label)gvOrchardData.FooterRow.FindControl("lblWateringNeeds")).Text;
dsOrchardDatabase.InsertParameters["OPollination"].DefaultValue =
((Label)gvOrchardData.FooterRow.FindControl("lblPollination")).Text;
dsOrchardDatabase.InsertParameters["OFertilizer"].DefaultValue =
((Label)gvOrchardData.FooterRow.FindControl("lblFertilizer")).Text;
dsOrchardDatabase.InsertParameters["OPesticide"].DefaultValue =
((Label)gvOrchardData.FooterRow.FindControl("lblPesticide")).Text;
dsOrchardDatabase.Insert();
}
Любая помощь была бы высоко оценена!
Эта стена текста, есть способ, вы можете изолировать проблему в меньшем примере? – Bloodied
Я понимаю Арессет.Вот первая сноска DDL: <жерех: DropDownList ID = "ddlTypeName" Runat = "сервер" AutoPostBack = "True" DataSourceID = "dsTypeName" DataTextField = "OrchardTypeName" DataValueField = "OrchardTypeID" > жерех: DropDownList> <% - подключены к строке соединения -%> FooterTemplate> на aspx.cs, вот что у меня есть: частная пустота ddlTypeName_SelectedIndexChanged (объект отправителя, EventArgs e) { // Необходимо включить ddlSpecies // Необходимо заполнить ddlSpecies на основе выбора ddlTypeName } –
Grey