Ich habe eine Gridview mit einer eigenen sqlDataSource. In der Fußzeile habe ich ein Einfügen-Feld, um eine neue Zeile zu erstellen. Allerdings ist diese Fußzeile ziemlich komplex und ich versuche herauszufinden, wie man es funktioniert.wie man eine Dropdownliste basierend auf der Auswahl einer anderen Dropdownliste in einer Gridview auffüllt
Was ich gerne sehen würde, ist, dass ein Benutzer die OTypeName ddl wählt. Basierend auf dieser Auswahl wird das OSpecies-ddl aktiviert und Werte basierend auf dem OTypeName-ddl aufgefüllt. Dasselbe kann in Bezug auf OSpecies und OVariety gesagt werden.
Der Benutzer gibt dann seine eigenen Informationen in OAge, OYields, OPlantDate und OPlantFrom ein.
Die übrigen Felder in der Fußzeile sind Beschriftungen, die basierend auf der letzten OVariety-Auswahl ausgefüllt werden.
Die Schaltfläche Einfügen fügt alle diese Spalten zur Gridview hinzu.
Ich brauche nur Hilfe beim Auffüllen eines ddl basierend auf der ddl-Auswahl eines anderen und wie man ein Label basierend auf einer ddl-Auswahl auffüllt.
Hier ist mein Code in der aspx-Datei:
<%@ 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>
Ich bin nicht sicher, was in der aspx.cs Datei zu setzen, aber hier ist das, was ich bisher über die Schaltfläche Einfügen:
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();
}
Jede Hilfe wäre sehr willkommen!
dass die Wand des Textes, ist es eine Möglichkeit, Sie können Isolieren Sie das Problem in einem kleineren Beispiel? – Bloodied
Ich verstehe Arescet.Hier ist die erste Fußzeile ddl: asp: Dropdownlist> <% - mit Verbindungszeichenfolge -%> FooterTemplate> auf dem aspx.cs, hier ist was ich habe: privater void ddlTypeName_SelectedIndexChanged (Objekt Absender, EventArgs e) { // Muss ddlSpecies aktivieren // Muss ddlSpecies basierend auf ddlTypeName Auswahl } –
Grey